node.js - Heroku 在 60 秒内无法绑定 PORT
问题描述
今天我将我的应用程序从创建反应应用程序移动到 SSR 的 razzle 但heroku 无法绑定端口,我阅读了其他问题但找不到这样的问题我已经正确设置了端口但仍然无法绑定它
"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`
解决方案
发现问题,
我正在使用RazzleJS
并且在生产过程中它会内联 PORT 环境或其他不以开头的环境RAZZLE_
有一些修复,但Razzle-heroku
在不更改任何代码的情况下运行良好。
推荐阅读
- webpack - 将动态导入捆绑到一个块中
- recursion - 意外递归,使用 Seq.append 炸毁堆栈,而不使用 `rec`
- java-8 - 番石榴到 Java 8 的转换
- java - Android Studio 运动模拟未按预期工作
- clojure - Clojure 惰性序列:Kotlin 中的等价物
- linux - Alfresco 5.2 高 CPU 利用率和应用程序性能低下
- javascript - 在 Elixir 中调用 JS api
- c# - 比较数据表和 SQL 表
- arrays - 出于数学目的声明矩阵的简单方法是什么?
- ios - CoreData fetch() 返回无序对象