fix(server): bootstrap HTTP server immediately and reconnect MongoDB in background to eliminate Bad Gateway
This commit is contained in:
parent
b38157b94a
commit
926b5c5fce
@ -282,10 +282,23 @@ const server = http.createServer(async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
await connectDatabase();
|
// 1. Iniciar servidor HTTP de inmediato para responder 200 OK a Traefik y visitantes
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
console.log(`🚀 [Servidor Transporte Cali - Buenaventura] Ejecutándose en puerto ${PORT}`);
|
console.log(`🚀 [Pacifictrans Go] Plataforma Web y API escuchando en puerto ${PORT}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 2. Conectar a MongoDB de forma no bloqueante con reintento automático
|
||||||
|
const tryConnect = async () => {
|
||||||
|
try {
|
||||||
|
await connectDatabase();
|
||||||
|
console.log('✅ [MongoDB] Conectado exitosamente en segundo plano.');
|
||||||
|
} catch (err: any) {
|
||||||
|
console.warn(`⚠️ [MongoDB Warning] Conexión no disponible (${err.message || 'ENOTFOUND'}). Reintentando en 10s...`);
|
||||||
|
setTimeout(tryConnect, 10000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
tryConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap().catch(console.error);
|
bootstrap().catch(console.error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user