In your POST-triggered push version, you are not keeping the stream open in the GET method for the '/sse' route. As a result, the stream gets closed, and your frontend is no longer able to read from it.
The only required modification is adding a while (true) loop to keep the stream open:
app.get('/sse', async (c) => {
return streamSSE(c, async (stream) => {
activeStreams.add(stream);
stream.onAbort(() => {
activeStreams.delete(stream);
});
// Send initial message (optional)
await stream.writeSSE({
data: `Connected at ${new Date().toISOString()}`,
event: "time-update",
id: String(id++),
});
// While-True loop to keep stream open
while (true) {
await stream.sleep(1000); // default delay
}
});
});
Please let me know whether this resolves your issue!