-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NextJS Usage #83
Comments
Hi there. Next.js is supported but unfortunately only when using API routes under the Pages Router as this library expects the Node You can use it like the following: // pages/api/sse.ts
import { createSession } from "better-sse";
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const session = await createSession(req, res);
session.push("Hello, world!");
} Route Handlers under the App Router instead give you the Request and Response objects from the Fetch API which won't be compatible, though support for this is planned in #79.
I'll add a usage snippet to the recipes section of the documentation with a note about compatibility. |
Thanks for the elaboration. Currently I use the App router, and this configuration is pushed as the default for new nextjs projects. I wasn't at all aware that there was an incompatibility. Generally I'm opposed to mixing usage of the Pages router with the App router, but if it's my only way forward until #79 is resolved then I guess I have little choice. I can't think of another workaround right now that would let me continue to exclusively use the App router. |
I'm trying to use better-see in a NextJS API Route, but I'm having trouble understanding how to go about it, and what precisely better-see expects in order to function correctly. The README claims compatibility with NextJS, but I'm having trouble finding any documentation or examples that support this.
I'm using NextJS 15.1.0 on node 20.18.1.
Here is some example code.
Which results in the following server error when a client attempts to listen on this route.
The text was updated successfully, but these errors were encountered: