File tree Expand file tree Collapse file tree 4 files changed +44
-1
lines changed
Expand file tree Collapse file tree 4 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -15,10 +15,12 @@ import { ValidacaoModule } from './validacao/validacao.module';
1515import { DadoModule } from './tipoDado/tipoDado.module' ;
1616import { ValorDadoModule } from './valorDado/valorDado.module' ;
1717import { RedisModule } from './redis/redis.module' ;
18+ import { HealthModule } from './health/health.module' ;
1819
1920@Module ( {
2021 imports : [
2122 ConfigModule . forRoot ( { isGlobal : true } ) ,
23+ HealthModule ,
2224 TypeOrmModule . forRoot ( {
2325 ...typeOrmConfig ,
2426 retryAttempts : 5 ,
Original file line number Diff line number Diff line change 1+ import { Controller , Get } from '@nestjs/common' ;
2+
3+ /**
4+ * Endpoint de health check para o Render e load balancers.
5+ * Responde 200 OK rapidamente, sem chamar Redis, DB ou MinIO.
6+ * Configure em Render: Health Check Path = /health
7+ */
8+ @Controller ( )
9+ export class HealthController {
10+ @Get ( 'health' )
11+ check ( ) {
12+ return { status : 'ok' } ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ import { Module } from '@nestjs/common' ;
2+ import { HealthController } from './health.controller' ;
3+
4+ @Module ( {
5+ controllers : [ HealthController ] ,
6+ } )
7+ export class HealthModule { }
Original file line number Diff line number Diff line change @@ -58,8 +58,28 @@ async function bootstrap() {
5858 app . useGlobalFilters ( new HttpExceptionFilter ( ) ) ;
5959
6060 const port = process . env . PORT || 3000 ;
61- await app . listen ( port , '0.0.0.0' ) ; // Escuta em todas as interfaces
61+ const server = await app . listen ( port , '0.0.0.0' ) ; // Escuta em todas as interfaces
62+
63+ // Ajustes recomendados pelo Render: evita ECONNRESET/socket hang up
64+ // por keep-alive e timeouts do load balancer (default 5s é curto)
65+ const httpServer = server as import ( 'http' ) . Server ;
66+ if ( httpServer ?. setTimeout ) {
67+ httpServer . keepAliveTimeout = 65000 ; // 65s
68+ httpServer . headersTimeout = 66000 ; // > keepAliveTimeout
69+ }
70+
6271 console . log ( `✅ Aplicação rodando na porta ${ port } ` ) ;
6372}
6473
74+ // Trata rejeições e exceções não capturadas para evitar crash por ECONNRESET
75+ // (ex.: falha em requisição HTTP para Upstash Redis, MinIO, etc.)
76+ process . on ( 'unhandledRejection' , ( reason : any , promise : Promise < unknown > ) => {
77+ console . error ( '[unhandledRejection]' , reason ?. message ?? reason ) ;
78+ } ) ;
79+
80+ process . on ( 'uncaughtException' , ( err : Error ) => {
81+ console . error ( '[uncaughtException]' , err . message , err . stack ) ;
82+ process . exit ( 1 ) ;
83+ } ) ;
84+
6585bootstrap ( ) ;
You can’t perform that action at this time.
0 commit comments