Skip to content
Discussion options

You must be logged in to vote

Yes, Next.js has a server API for exactly this kind of setup. I’ve used it with a self-hosted Docker Compose stack on AWS, and I have full hot-reloading for both NextJS and Server code in development.

The essential server setup is very small:

import http from "http";
import next from "next";

const port = Number(process.env.APPLICATION_PORT);
const dev = process.env.NODE_ENV !== "production";

// Enables Next.js development mode, including Fast Refresh.
const app = next({ dev, port });

await app.prepare();

const handle = app.getRequestHandler();

http.createServer((req, res) => {
  handle(req, res);
}).listen(port);

The key line is:

const app = next({ dev, port });

When dev is true, Nex…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by HollyWaymack

This comment was marked as low quality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants