我正在尝试使用SSH(Putty)运行nextjs应用程序
登录后,我导航到应用程序的根目录并运行
screen -S screen_name
要在此之后启动新屏幕,我运行:
npm run start
然后我得到这个
> @iso/next@4.0.0 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应用程序做了同样的事情,我能够运行它,没有任何问题
我做错什么了吗?
1条答案
按热度按时间pkwftd7m1#
应用程序似乎在指定端口上成功运行,但您无法从外部访问它...