diff --git a/app/server.ts b/app/server.ts index de270ee..f7714e8 100644 --- a/app/server.ts +++ b/app/server.ts @@ -23,6 +23,8 @@ const app = next({ dev, hostname, port }); const handle = app.getRequestHandler(); app.prepare().then(() => { + const nextUpgradeHandler = app.getUpgradeHandler(); + const httpServer = createServer((req, res) => { handle(req, res); }); @@ -33,7 +35,8 @@ app.prepare().then(() => { httpServer.on("upgrade", (req, socket, head) => { const { pathname } = new URL(req.url ?? "/", "http://internal"); if (pathname !== "/ws/runs") { - socket.destroy(); + // Anything else (e.g. Next's own dev-mode HMR websocket at /_next/hmr) is Next's to handle. + nextUpgradeHandler(req, socket, head).catch(() => socket.destroy()); return; }