(req: Request, res: Response)
| 68 | } |
| 69 | |
| 70 | export function apiLogsStream(req: Request, res: Response): void { |
| 71 | res.writeHead(200, { |
| 72 | 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', |
| 73 | 'Connection': 'keep-alive', 'X-Accel-Buffering': 'no', |
| 74 | }); |
| 75 | const sse = (event: string, data: string) => 'event: ' + event + '\ndata: ' + data + '\n\n'; |
| 76 | try { res.write(sse('stats', JSON.stringify(getStats()))); } catch { /**/ } |
| 77 | const unsubLog = subscribeToLogs(e => { try { res.write(sse('log', JSON.stringify(e))); } catch { /**/ } }); |
| 78 | const unsubSummary = subscribeToSummaries(s => { |
| 79 | try { res.write(sse('summary', JSON.stringify(s))); res.write(sse('stats', JSON.stringify(getStats()))); } catch { /**/ } |
| 80 | }); |
| 81 | const hb = setInterval(() => { try { res.write(': heartbeat\n\n'); } catch { /**/ } }, 15000); |
| 82 | req.on('close', () => { unsubLog(); unsubSummary(); clearInterval(hb); }); |
| 83 | } |
| 84 | |
| 85 | // ==================== 页面服务 ==================== |
| 86 |
nothing calls this directly
no test coverage detected