Heartbeat and nicer status line
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user