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);