Heroku在60秒内未能绑定PORT

时间:2019-02-13 18:15:10

标签: node.js heroku

今天,我将我的应用程序从create react app移到了对SSR狂热的状态,但是heroku无法绑定PORT, 我读了其他问题,但找不到这样的问题 我已经正确设置了端口,但仍然无法绑定

"scripts": {
"dev": "razzle start",
"build": "razzle build",
"test": "razzle test --env=jsdom",
"start": "NODE_ENV=production node build/server.js",
"heroku-postbuild": "yarn build"
},

 // const port = process.env.PORT || 4000;
export default express()
.use((req, res) => app.handle(req, res))
.listen(process.env.PORT || 4000, function(err) {
  if (err) {
  console.error(err);
  return;
}
console.log(`> Started server`);
});

日志

2019-02-13T17:56:08.700969+00:00 app[web.1]: > NODE_ENV=production 
node build/server.js
2019-02-13T17:56:08.700971+00:00 app[web.1]: 
2019-02-13T17:56:10.910281+00:00 app[web.1]: > Started server
2019-02-13T17:56:12.000000+00:00 app[api]: Build succeeded
2019-02-13T17:57:05.112846+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-13T17:57:05.119328+00:00 heroku[web.1]: State changed from crashed to starting
2019-02-13T17:57:04.991380+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-02-13T17:57:04.991503+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-02-13T17:57:05.096022+00:00 heroku[web.1]: Process exited with status 137
2019-02-13T17:57:18.472313+00:00 heroku[web.1]: Starting process with command `npm start`
2019-02-13T17:57:21.719632+00:00 app[web.1]: 
2019-02-13T17:57:21.719660+00:00 app[web.1]: > *`enter code here`@2.0.1 start /app
2019-02-13T17:57:21.719662+00:00 app[web.1]: > NODE_ENV=production node build/server.js
2019-02-13T17:57:21.719663+00:00 app[web.1]: 
2019-02-13T17:57:23.071400+00:00 app[web.1]: > Started server
2019-02-13T17:57:36.325346+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=*.herokuapp.com request_id=d322452e-de5a-479b-831a-a0345864671d 
fwd="193.172.191.16" dyno= connect= service= status=503 bytes= protocol=https`

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,并将端口从

更改
const app = express()
const port = 8000
app.listen(port)

.listen(process.env.PORT || 8000)

为我解决了这个问题

但是当我研究时,我发现这个答案可能会有所帮助

https://github.com/keystonejs/keystone/issues/3994#issuecomment-280639251

它基本上说从package.json中删除它可以解决问题
"engines": {
    "node": ">=0.10.22",
    "npm": ">=1.3.14"
  },

答案 1 :(得分:0)

发现了问题,

我正在使用RazzleJS,并且在生产过程中会内联PORT环境或其他以RAZZLE_开头的环境

有一些修复程序,但是Razzle-heroku在不更改任何代码的情况下运行良好。