Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.
This repository was archived by the owner on May 26, 2025. It is now read-only.

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

Open
@yoieh

Description

@yoieh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions