test(streaming): more testing on streaming the lofs

This commit is contained in:
2025-03-22 08:21:11 -05:00
parent 4db4eea2d1
commit e82ef76316
2 changed files with 35 additions and 6 deletions

View File

@@ -29,12 +29,23 @@ app.openapi(
}),
async (c) => {
apiHit(c, {endpoint: `api/logger/logs`});
c.header("Access-Control-Allow-Origin", "*"); // Or restrict to a specific origin
c.header("Access-Control-Allow-Headers", "Content-Type");
c.header("Content-Type", "text/event-stream");
c.header("Cache-Control", "no-cache");
c.header("Connection", "keep-alive");
return streamLogs(c);
return streamSSE(c, async (stream) => {
let id = 0;
const encoder = new TextEncoder();
while (true) {
const message = `It is ${new Date().toISOString()}`;
await stream.writeSSE({
data: message,
event: "time-update",
id: String(id++),
});
encoder.encode(`data: ${JSON.stringify({type: "progress", data: id})}\n\n`);
await stream.sleep(1000);
}
});
}
);
export default app;