Next.js Discord

Discord Forum

HMR with custom server

Unanswered
Derock posted this in #help-forum
Open in Discord
Avatar
so far, I've figured out you can get an upgrade handler (similar to the request handler) with nextApp.getUpgradeHandler()
but the function being returned is a noop:
// node_modules/next/dist/server/next-server.js:198
    async handleUpgrade() {
    // The web server does not support web sockets, it's only used for HMR in
    // development.
    }


I verified this by adding a throw new Error("...") into the function and called.
I am creating my next.js app like this:
import next from "next";

const nextApp = next({ 
  dev: env.dev, // I've console.log'd this and confirmed it is `true`
  hostname: env.host,
  port: env.port,
});

await nextApp.prepare(); // I have top level await support
const handle = nextApp.getRequestHandler();
const handleUpgrade = nextApp.getUpgradeHandler();

0 Replies