From 926b5c5fce2b3b5c20e03719100f3c604883ca38 Mon Sep 17 00:00:00 2001 From: AI Bot Date: Tue, 13 Oct 2026 19:38:41 -0500 Subject: [PATCH] fix(server): bootstrap HTTP server immediately and reconnect MongoDB in background to eliminate Bad Gateway --- .../backend/src/index.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/transporte-cali-buenaventura/backend/src/index.ts b/transporte-cali-buenaventura/backend/src/index.ts index 3a8d7f8..d554e6a 100644 --- a/transporte-cali-buenaventura/backend/src/index.ts +++ b/transporte-cali-buenaventura/backend/src/index.ts @@ -282,10 +282,23 @@ const server = http.createServer(async (req, res) => { }); async function bootstrap() { - await connectDatabase(); + // 1. Iniciar servidor HTTP de inmediato para responder 200 OK a Traefik y visitantes 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);