From 6d7f95fc717695f84b6c8350540c83a6f8740d8e Mon Sep 17 00:00:00 2001 From: josedario87 Date: Mon, 9 Jun 2025 17:36:27 -0600 Subject: [PATCH] seguimos habilitando la funcion realtime --- api/sse/index.js | 16 ++++++++++------ ui/nginx.conf | 13 +++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/api/sse/index.js b/api/sse/index.js index be9a908..1c68c9e 100644 --- a/api/sse/index.js +++ b/api/sse/index.js @@ -7,19 +7,23 @@ export function registerSse(app) { res.set({ 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', - Connection: 'keep-alive' + 'Connection': 'keep-alive' }); - res.flushHeaders(); - res.write(':\n\n'); - sseClients.push(res); - res.on('close', () => { + res.flushHeaders(); + res.write('event: connected\ndata: {}\n\n'); // ← mantiene el stream vivo + + sseClients.push(res); + console.log(`🟢 Cliente SSE conectado (${sseClients.length})`); + + req.on('close', () => { const idx = sseClients.indexOf(res); if (idx !== -1) sseClients.splice(idx, 1); - res.end(); + console.log(`🔌 Cliente SSE desconectado (${sseClients.length})`); }); }); + const broadcast = (data) => { const payload = `data: ${data}\n\n`; sseClients.forEach((client) => client.write(payload)); diff --git a/ui/nginx.conf b/ui/nginx.conf index 2f45f04..12a1dfb 100644 --- a/ui/nginx.conf +++ b/ui/nginx.conf @@ -9,6 +9,19 @@ server { try_files $uri $uri/ /index.html; } + + location /events { + proxy_pass http://planilla-api:4000; + proxy_http_version 1.1; + proxy_set_header Connection ''; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; +} + + location /config.js { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Content-Type' 'application/javascript';