Replies: 1 comment
-
you may check showcase_chat example. The example use SSE inside this handler import { Handlers, RouteConfig } from "$fresh/server.ts";
import { RoomChannel } from "@/communication/channel.ts";
export const handler: Handlers = {
GET(_req, ctx) {
const channel = new RoomChannel(+ctx.params.room);
const stream = new ReadableStream({
start: (controller) => {
channel.onMessage((message) => {
const body = `data: ${JSON.stringify(message)}\n\n`;
controller.enqueue(body);
});
},
cancel() {
channel.close();
},
});
return new Response(stream.pipeThrough(new TextEncoderStream()), {
headers: { "content-type": "text/event-stream" },
});
},
};
export const config: RouteConfig = {
routeOverride: "/api/connect/:room",
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying out using Aleph for a new project I'm working on and I love it so far, but I'm struggling to utilize server-side events as part of the API. I know Oak supports SSE, but I can't figure out how to integrate it to Aleph's API framework if that's even possible. I'm very new to SSE so although I'm currently trying to implement it myself I'd be much happier with a built-in/library way of doing it. Does anyone know how that could work?
Beta Was this translation helpful? Give feedback.
All reactions