Heroku返回错误'Web进程未能在启动后60秒内绑定到$PORT'使用process.env.POR



这是我的NodeJS服务器

const fastify = require('fastify');
const JWT = require('jsonwebtoken');
const server_manifest = require('./manifest.json');
(async ()=>{
const server = fastify(server_manifest.fastify_options)
const routes = await require('./routes/index')();
routes.forEach( route => {
server.route(route)
})
const server_port = process.env.PORT || 80
await server.listen(server_port)
console.log(`Listening to port ${server_port}`)
} )()

我正在使用Heroku CLI来部署我的应用程序。

在将repo推送到Heroku I后,它返回构建成功,但服务器无法与Heroku上的任何端口绑定。

来自heroku的日志:

2020-10-14T19:34:11.000000+00:00 app[api]: Build started by user rishavbhowmik@outlook.com
2020-10-14T19:34:24.744074+00:00 app[api]: Release v8 created by user rishavbhowmik@outlook.com
2020-10-14T19:34:24.744074+00:00 app[api]: Deploy c5ce6232 by user rishavbhowmik@outlook.com
2020-10-14T19:34:25.000000+00:00 app[api]: Build succeeded
2020-10-14T19:34:25.420753+00:00 heroku[web.1]: State changed from crashed to starting
2020-10-14T19:34:27.634828+00:00 heroku[web.1]: Starting process with command `npm start`
2020-10-14T19:34:30.313002+00:00 app[web.1]:
2020-10-14T19:34:30.313020+00:00 app[web.1]: > tsotang_web@1.0.0 start /app
2020-10-14T19:34:30.313021+00:00 app[web.1]: > node server.js
2020-10-14T19:34:30.313021+00:00 app[web.1]:
2020-10-14T19:34:30.674062+00:00 app[web.1]: {"level":30,"time":1602704070673,"pid":23,"hostname":"ed54244a-ed04-45a8-903e-428a8b57f725","msg":"Server listening at http://127.0.0.1:17850"}
2020-10-14T19:34:30.676814+00:00 app[web.1]: Listening to port 17850
2020-10-14T19:35:27.702639+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-10-14T19:35:27.736001+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-10-14T19:35:27.873461+00:00 heroku[web.1]: Process exited with status 137
2020-10-14T19:35:27.923509+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-14T19:35:27.926649+00:00 heroku[web.1]: State changed from crashed to starting
2020-10-14T19:35:42.981476+00:00 heroku[web.1]: Starting process with command `npm start`
2020-10-14T19:35:48.230394+00:00 app[web.1]:
2020-10-14T19:35:48.230408+00:00 app[web.1]: > tsotang_web@1.0.0 start /app
2020-10-14T19:35:48.230409+00:00 app[web.1]: > node server.js
2020-10-14T19:35:48.230409+00:00 app[web.1]:
2020-10-14T19:35:50.170208+00:00 app[web.1]: {"level":30,"time":1602704150142,"pid":23,"hostname":"bc2dd20b-2d49-4db4-b62a-cc2d34bfffdb","msg":"Server listening at http://127.0.0.1:28541"}
2020-10-14T19:35:50.186877+00:00 app[web.1]: Listening to port 28541
2020-10-14T19:36:43.479233+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-10-14T19:36:43.504937+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-10-14T19:36:43.625303+00:00 heroku[web.1]: Process exited with status 137
2020-10-14T19:36:43.678738+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-14T19:36:46.409789+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=jovialblogs.herokuapp.com request_id=aca75a5a-a6ee-45bf-8f36-69b17d41c731 fwd="49.36.133.90" dyno= connect= service= status=503 bytes= protocol=https
2020-10-14T19:36:47.606655+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=jovialblogs.herokuapp.com request_id=3ad806e9-2782-4501-9aea-ebe732e0e93d fwd="49.36.133.90" dyno= connect= service= status=503 bytes= protocol=https

您应该手动指定"0.0.0.0"主机,例如:

const host = '0.0.0.0';
await server.listen(server_port, host);

相关内容

最新更新