Skip to content

Commit d55ec5c

Browse files
committed
fix: adjust ngrok
1 parent 63b7d37 commit d55ec5c

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import { ValidacaoModule } from './validacao/validacao.module';
1515
import { DadoModule } from './tipoDado/tipoDado.module';
1616
import { ValorDadoModule } from './valorDado/valorDado.module';
1717
import { 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,

src/health/health.controller.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

src/health/health.module.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Module } from '@nestjs/common';
2+
import { HealthController } from './health.controller';
3+
4+
@Module({
5+
controllers: [HealthController],
6+
})
7+
export class HealthModule {}

src/main.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
6585
bootstrap();

0 commit comments

Comments
 (0)