Heartbeat and nicer status line

This commit is contained in:
2026-05-09 13:47:37 -03:00
parent 7b5d4afd07
commit 62043b1f8f
2 changed files with 27 additions and 3 deletions
+11 -2
View File
@@ -18,6 +18,7 @@ const DATA_DIR = process.env.DATA_DIR || './data';
const PAGE_SIZE_MAX = 48;
const UPLOAD_MAX_BYTES = 5 * 1024 * 1024;
const REQUEST_MAX_BYTES = 6 * 1024 * 1024;
const SSE_HEARTBEAT_MS = 25_000;
const events = new Set();
const DISCOVERY_ROUTES = new Set([
'/robots.txt',
@@ -135,11 +136,19 @@ const server = http.createServer(async (req, res) => {
res.writeHead(200, {
'Content-Type': 'text/event-stream; charset=utf-8',
'Cache-Control': 'no-cache, no-transform',
Connection: 'keep-alive'
Connection: 'keep-alive',
'X-Accel-Buffering': 'no'
});
res.write('retry: 5000\n');
res.write('event: ready\ndata: {}\n\n');
events.add(res);
req.on('close', () => events.delete(res));
const heartbeat = setInterval(() => {
res.write(': keep-alive\n\n');
}, SSE_HEARTBEAT_MS);
req.on('close', () => {
clearInterval(heartbeat);
events.delete(res);
});
return;
}