Hey everyone
The problem
I can’t keep the server sent event connection alive for more than ~1 minute
I get this error in the browser console
GET https://domain.com/api/sse 502
This is my resource route loader code
import { eventStream } from "remix-utils";
import { emitter } from "~/utils/notification/emitter.server";
import { Events, EventsType } from "~/utils/notification/events";
import { requireUser } from "~/utils/sessions/user.server";
import type { Notification } from "@prisma/client";
export async function loader({ request }: LoaderArgs) {
const user = await requireUser(request);
return eventStream(request.signal, function setup(send) {
function handle(notification: Notification) {
if (notification.userId !== user.id) return;
send({ event: Events.newNotification, data: notification.id });
}
emitter.on(EventsType.notification, handle);
return function clear() {
emitter.off(EventsType.notification, handle);
};
});
}
the event works fine for about a minute then not