Heroku 应用程序启动超时 (R10) - NodeJs

Heroku app timeout on boot (R10) - NodeJs

我正在使用 process.env.PORT,这在日志中显示(见下文,localhost:40170,每次我 运行 应用程序都会更改)。此外,加载时间很快(10 秒),因为我没有 运行 在节点启动时设置任何构建过程。 运行 heroku local 运行s 应用正常。请帮助我找出可能导致此问题的原因。

这是日志:

2018-05-03T02:37:04.505544+00:00 app[web.1]: loading routes from ./modules/user.login/auth.routes.js... 2018-05-03T02:37:04.526922+00:00 app[web.1]: loading routes from ./modules/user.login/login.routes.js... 2018-05-03T02:37:04.531738+00:00 app[web.1]: loading routes from ./modules/feature.clientes/clientes.crud.routes.js... 2018-05-03T02:37:04.542719+00:00 app[web.1]: loading routes from ./modules/feature.contratos/contratos.crud.routes.js... 2018-05-03T02:37:04.552200+00:00 app[web.1]: loading routes from ./modules/feature.servicos/servicos.crud.routes.js... 2018-05-03T02:37:04.601525+00:00 app[web.1]: Server running at: http://localhost:40170 2018-05-03T02:38:01.800290+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 2018-05-03T02:38:01.800290+00:00 heroku[web.1]: Stopping process with SIGKILL 2018-05-03T02:38:01.899194+00:00 heroku[web.1]: Process exited with status 137 2018-05-03T02:38:01.940085+00:00 heroku[web.1]: State changed from starting to crashed

不看你的一些代码就不可能知道。如果我不得不猜测,有一个依赖你在本地满足你在服务器上不满意,比如 DH 连接,或者你可能没有在你的 package.json 中包含你在本地安装的模块(例如全局安装)

This seems to be happen as because heroku sets dynamic port at which your app runs, as you are using PORT from env you need to add PORT in heroku config vars. Just got through heroku app => settings => view config vars => Add PORT <your port number example 5000> in it.

解决了:除了,还有别的。

我已经将我的 Hapi 服务器的 host 选项从 '0.0.0.0' 更改为 'localhost'(可能是因为它不是本地的 运行)。根据 Hapi's API reference,这是自动完成的 - 首先它尝试机器名称,然后 'localhost'。

因此只需删除该设置即可解决问题。现在 Heroku 记录如下内容:Server running at: http://243c893-1ec-48d-bdc4-2ba08a3d59:55296