const path = require("path"); const express = require("express"); const next = require("next"); const port = parseInt(process.env.PORT || "3000", 10); const hostname = process.env.HOSTNAME || "0.0.0.0"; const app = next({ dev: false, hostname, port }); const handle = app.getRequestHandler(); app .prepare() .then(() => { const server = express(); // Serve Next.js build assets and public files explicitly. server.use("/_next/static", express.static(path.join(__dirname, ".next", "static"))); server.use(express.static(path.join(__dirname, "public"))); server.all("*", (req, res) => handle(req, res)); server.listen(port, hostname, () => { console.log(`Server listening on http://${hostname}:${port}`); }); }) .catch((err) => { console.error("Failed to start server", err); process.exit(1); });