我有一个由 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"
}
}
有时,该网站甚至无法加载!
任何帮助是极大的赞赏 !
谢谢 !