我正在尝试使用 SSH (Putty) 运行 nextjs 应用程序
登录后,我导航到应用程序的根目录并运行
screen -S screen_name
在我运行之后开始新屏幕:
npm run start
然后我明白了:
> @iso/[email protected] start
> NODE_ENV=production node server.js
> Ready on http://localhost:3200
但是当我尝试在线查看应用程序时,它显示:
The connection has timed out
这里是 server.js 文件:
const { createServer } = require("http");
const { parse } = require("url");
const next = require("next");
const dev = process.env.NODE_ENV !== "production";
const hostname = "localhost";
const port = process.env.port || 3200;
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer(async (req, res) => {
try {
// Be sure to pass `true` as the second argument to `url.parse`.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true);
const { pathname, query } = parsedUrl;
if (pathname === "/a") {
await app.render(req, res, "/a", query);
} else if (pathname === "/b") {
await app.render(req, res, "/b", query);
} else {
await handle(req, res, parsedUrl);
}
} catch (err) {
console.error("Error occurred handling", req.url, err);
res.statusCode = 500;
res.end("internal server error");
}
}).listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://${hostname}:${port}`);
});
});
我对另一个 nextjs 应用程序做了同样的事情,我能够毫无问题地运行它
我在这里做错了什么吗?
看起来应用程序在指定端口上运行成功,但是您无法从外部访问它...