MCPcopy
hub / github.com/7836246/cursor2api / apiLogsStream

Function apiLogsStream

src/log-viewer.ts:70–83  ·  view source on GitHub ↗
(req: Request, res: Response)

Source from the content-addressed store, hash-verified

68}
69
70export 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

Callers

nothing calls this directly

Calls 6

sseFunction · 0.85
getStatsFunction · 0.85
subscribeToLogsFunction · 0.85
subscribeToSummariesFunction · 0.85
writeHeadMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected