Skip to content
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

Support new the app directory's Route Handlers of Next.js v13.3 #8

Open
yoieh opened this issue Apr 10, 2023 · 1 comment
Open

Support new the app directory's Route Handlers of Next.js v13.3 #8

yoieh opened this issue Apr 10, 2023 · 1 comment

Comments

@yoieh
Copy link

yoieh commented Apr 10, 2023

Expected working example:

import { NextApiHandler } from "next";
import { NextWebSocketHandler } from "next-plugin-websocket";

export const socket: NextWebSocketHandler = (client, req) => {
  console.log("Client connected");

  client.on("message", (msg) => {
    client.send(msg);
  });

  client.on("close", () => {
    console.log("Client disconnected");
  });
};

export async function GET(request: Request) {
  return new Response("Upgrade Required", {
    status: 426,
  });
}

After PR #6 has been merged it will give an error if you try and use the above example.

error - unhandledRejection: PageNotFoundError: Cannot find module for page: /api/ws
    at findPagePathData (.../node_modules/next/dist/server/dev/on-demand-entry-handler.js:272:15)
    at async Object.ensurePage (.../node_modules/next/dist/server/dev/on-demand-entry-handler.js:444:38)
    at async Server.<anonymous> (.../node_modules/next-plugin-websocket/dist/index.js:88:13) {
  code: 'ENOENT'
}

It only works with the old pages directory.

@yoieh
Copy link
Author

yoieh commented Apr 11, 2023

I tried get my self a deeper understanding of how this would work with the new app dir in 13.3.

Even if you find and require the route file socket never gets exported.

May need to find a different approach here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant