使用 Heroku 进行 Fastify

2023-12-19

我有一个由 Heroku 托管的简单 Fastify 服务器。但是,似乎不起作用!但是,在开发过程中,似乎一切都好!我得到的错误是:Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch。我收到的完整错误:

这是我正在使用的代码:
server.js:

const fastify = require("fastify")();
const path = require("path");

fastify.register(require("fastify-static"), {
  root: path.join(__dirname, "/"),
});

fastify.get("/", function (req, reply) {
  reply.sendFile("index.html");
});

fastify.listen(process.env.PORT || 5000, (err) => {
  if (err) throw err;
  console.log(`server listening on ${fastify.server.address().port}`);
});

package.json:

{
"name": "test1",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "engines": {
    "node": "15.11.x"
  },
  "scripts": {
    "start": "node server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "fastify": "^3.14.0",
    "fastify-static": "^4.0.1"
  }
}

有时,该网站甚至无法加载!
任何帮助是极大的赞赏 !
谢谢 !


这是图书馆的问题。对于其他库(express、django 等),不需要指定地址。

See https://github.com/fastify/fastify/issues/709 https://github.com/fastify/fastify/issues/709

Change:

.listen(process.env.PORT) 

to:

.listen(process.env.PORT, '0.0.0.0')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Heroku 进行 Fastify 的相关文章

随机推荐