The standalone next package is trimmed and doesn't include webpack. The custom server.js was using next() which triggers config loading that requires webpack. Fix by extracting the standalone config at build time and setting __NEXT_PRIVATE_STANDALONE_CONFIG before requiring next, matching what the generated standalone server does.
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
const { createServer } = require("http");
|
|
const path = require("path");
|
|
const { parse } = require("url");
|
|
|
|
const dev = process.env.NODE_ENV !== "production";
|
|
const hostname = process.env.HOSTNAME || "0.0.0.0";
|
|
const port = parseInt(process.env.PORT || "3100", 10);
|
|
|
|
// In production, load the standalone config to avoid webpack dependency
|
|
if (!dev) {
|
|
try {
|
|
const configPath = path.join(__dirname, "next-config.json");
|
|
const nextConfig = JSON.parse(require("fs").readFileSync(configPath, "utf8"));
|
|
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(nextConfig);
|
|
} catch {
|
|
// Config not found (local dev) — next() will load config normally
|
|
}
|
|
}
|
|
|
|
const next = require("next");
|
|
const { attachPtyWebSocket } = require("./pty-server");
|
|
|
|
const app = next({ dev, hostname, port, dir: __dirname });
|
|
const handle = app.getRequestHandler();
|
|
|
|
app.prepare().then(() => {
|
|
const server = createServer((req, res) => {
|
|
const parsedUrl = parse(req.url || "/", true);
|
|
handle(req, res, parsedUrl);
|
|
});
|
|
|
|
attachPtyWebSocket(server);
|
|
|
|
server.listen(port, hostname, () => {
|
|
console.log(`> Harness ready on http://${hostname}:${port}`);
|
|
});
|
|
});
|