我有一个与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"
}
}有时,网站甚至不加载!
任何帮助都是非常感谢的!
谢谢!
发布于 2021-03-22 10:24:28
这是图书馆的问题。其他图书馆(特快、django等)没有必要指定地址。
请参阅https://github.com/fastify/fastify/issues/709
更改:
.listen(process.env.PORT) 至:
.listen(process.env.PORT, '0.0.0.0')发布于 2022-01-27 21:27:24
当我同时使用nodemon作为本地服务器和Heroku进行生产时,以下工作对我来说是可行的:
await fastify.listen(process.env.PORT, process.env.HOST || '0.0.0.0');在package.json中
"dev": "PORT=${PORT:=3000} HOST=${HOST:=localhost} nodemon"https://stackoverflow.com/questions/66743455
复制相似问题