我在package.json中使用此代码,并且想要部署到heroku应用
"scripts": {
"build": "cd app && next build",
"start": "npm run build && env NODE_ENV=production node app.js",
"dev": "nodemon --ignore app/ app.js"
},
我也尝试过:
"start": "next start -p $PORT",
我正在使用此样板: https://github.com/MustansirZia/next-express-bootstrap-boilerplate
答案 0 :(得分:0)
我认为它运行在错误的端口上。 Heroku会将端口作为env变量提供给您,但是您的应用程序需要从环境中获取端口,然后在启动时使用它。
在app.js中将其添加到顶部(将默认端口更改为所需的端口)。它将从环境变量PORT中获取端口,如果不存在,则默认为3000:
const port = process.env.PORT || 3000;
然后在最底部,将最后一行更改为此
start(port);