简体   繁体   English

错误 R10(启动超时)-> Web 进程未能在启动后 60 秒内绑定到 $PORT - HEROKU 错误

[英]Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch - HEROKU ERROR

I deployed my Node.js WebApp to heroku but I'm getting this error我将 Node.js WebApp 部署到 heroku 但出现此错误

2021-06-01T09:19:42.615419+00:00 heroku[web.1]: State changed from crashed to starting
2021-06-01T09:19:47.259832+00:00 heroku[web.1]: Starting process with command `node app.js`
2021-06-01T09:19:51.146182+00:00 app[web.1]: Server is running on port 3001.
2021-06-01T09:20:47.916699+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to 
bind to $PORT within 60 seconds of launch
2021-06-01T09:20:47.989032+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-06-01T09:20:48.124402+00:00 heroku[web.1]: Process exited with status 137
2021-06-01T09:20:48.196055+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-01T09:24:45.072782+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET 
path="/" host=positate.herokuapp.com request_id=7e9ec2b1-5685-4c3f-9c29-6c03268b7c82 
fwd="157.51.56.186" dyno= connect= service= status=503 bytes= protocol=https
2021-06-01T09:24:46.540443+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET 
path="/favicon.ico" host=positate.herokuapp.com request_id=4ab44a6a-4795-4a4d-b32d-28d796845774 
fwd="157.51.56.186" dyno= connect= service= status=503 bytes= protocol=https

I'm attaching my app.js here我在这里附上我的 app.js

 require("dotenv").config(); const express = require("express"); const app = express(); const ejs = require("ejs"); const mongoose = require("mongoose"); const session = require("express-session"); const passport = require("passport"); const passportLocalMongoose = require("passport-local-mongoose"); const GoogleStrategy = require("passport-google-oauth20").Strategy; const findOrCreate = require("mongoose-findorcreate"); const timestamp = require("mongoose-timestamp"); const MongoStore = require('connect-mongo'); const auth = require("./routes/auth"); const User = require("./database/models/user_model"); const blogRoute = require("./routes/blogRoute"); mongoose.connect(process.env.DB_URI, { useNewUrlParser: true, useUnifiedTopology: true, }); mongoose.set("useCreateIndex", true); mongoose.set("useFindAndModify", false); app.use(express.static("public")); app.set("view engine", "ejs"); app.use(express.urlencoded({ extended: true })); app.use(express.json()); app.use(session({ secret: "foo", saveUninitialized: false, resave: false, store: MongoStore.create({ mongoUrl: process.env.DB_URI, mongoOptions: { useUnifiedTopology: true }, collectionName: 'sessions', autoRemove: 'native', }) })); app.use(passport.initialize()); app.use(passport.session()); passport.use(User.createStrategy()); passport.serializeUser(function (user, done) { done(null, user.id); }); passport.deserializeUser(function (id, done) { User.findById(id, function (err, user) { done(err, user); }); }); passport.use( new GoogleStrategy( { clientID: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, callbackURL: "http://localhost:3001/auth/google/positate" || "https://positate.herokuapp.com/auth/google/positate", }, function (accessToken, refreshToken, profile, cb) { User.findOrCreate( { googleId: profile.id, name: profile.displayName, username: profile.emails[0].value, image: profile.photos[0].value, }, function (err, user) { return cb(err, user); } ); } ) ); app.get("/", (req, res) => { res.render("Landing"); }); app.use("/", auth); app.use("/blog", blogRoute); app.use("/", blogRoute); app.use("/category", blogRoute); app.listen(3001 || process.env.PORT, '0.0.0.0', () => { console.log("Server is running."); });
This is my Procfile 这是我的 Procfile

{
  "name": "positate",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "engines": {
    "node": "14.15.4",
    "npm": "6.14.10"
  },
  "scripts": {
    "start": "node app.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "connect-mongo": "^4.4.1",
    "dotenv": "^10.0.0",
    "ejs": "^3.1.6",
    "express": "^4.17.1",
    "express-session": "^1.17.2",
    "mongoose": "^5.12.11",
    "mongoose-findorcreate": "^3.0.0",
    "mongoose-timestamp": "^0.6.0",
    "passport": "^0.4.1",
    "passport-google-oauth20": "^2.0.0",
    "passport-local": "^1.0.0",
    "passport-local-mongoose": "^6.1.0"
  }
}

This is my package.json这是我的 package.json

 { "name": "positate", "version": "1.0.0", "description": "", "main": "app.js", "engines": { "node": "14.15.4", "npm": "6.14.10" }, "scripts": { "start": "node app.js" }, "author": "", "license": "ISC", "dependencies": { "connect-mongo": "^4.4.1", "dotenv": "^10.0.0", "ejs": "^3.1.6", "express": "^4.17.1", "express-session": "^1.17.2", "mongoose": "^5.12.11", "mongoose-findorcreate": "^3.0.0", "mongoose-timestamp": "^0.6.0", "passport": "^0.4.1", "passport-google-oauth20": "^2.0.0", "passport-local": "^1.0.0", "passport-local-mongoose": "^6.1.0" } }

I tried various solutions for this error but was not able to solve it.我为此错误尝试了各种解决方案,但无法解决。 I've been trying to solve this for the past three days.在过去的三天里,我一直在努力解决这个问题。 Kindly help me solve this error Thank you so much in Advance.请帮我解决这个错误 非常感谢您提前。

The issue is the way you define the port, it always runs on 3001 which is not possible on Heroku, you need to bind the $PORT env variable.问题是您定义端口的方式,它始终在3001上运行,这在 Heroku 上是不可能的,您需要绑定$PORT环境变量。
Change your code to check first fi the process.env.PORT is defined (it will be on Heroku but on your local dev environment it will default to 3001)更改您的代码以首先检查是否定义了process.env.PORT (它将位于 Heroku 但在您的本地开发环境中默认为 3001)

app.listen(process.env.PORT || 3001, '0.0.0.0', () => {
  console.log("Server is running.");
});

See NodeJS on Heroku请参阅Heroku 上的 NodeJS

Remove the engines from your package.json and try running it again.从 package.json 中卸下引擎,然后再次尝试运行它。 It looks like there was an issue related to this似乎存在与此相关的问题

Source 资源

I had the same issue and it drove me mad for plenty of time.我有同样的问题,它让我发疯了很长时间。

The fix was to configure my webserver to do BOTH of the following:解决方法是将我的网络服务器配置为执行以下两项操作:

  1. automatically pick up port from process.env.PORT (also known as the $PORT environment variable. Heroku sets this automatically at deployment time.)自动从process.env.PORT获取端口(也称为$PORT环境变量。Heroku 在部署时自动设置。)
  2. listen explicitly at the address 0.0.0.0 ( locahost didn't work!)在地址0.0.0.0明确收听( locahost不起作用!)

Turns out Heroku is explaining this in their help guide already:原来 Heroku 已经在他们的帮助指南中解释了这一点:

In rarer cases, your app may be using process.env.PORT , but may still be failing to bind.在极少数情况下,您的应用可能正在使用process.env.PORT ,但仍可能无法绑定。 This can be caused by the app attempting to bind on localhost .这可能是由于应用程序尝试在localhost上绑定造成的。 Instead, you may need to change this to 0.0.0.0 .相反,您可能需要将其更改为0.0.0.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Heroku || 错误 R10(启动超时)-> Web 进程未能在启动后 60 秒内绑定到 $PORT - Heroku || Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch Node.js将错误上传到Heroku,Web进程在启动后60秒内未能绑定到$ PORT - Node.js upload error to Heroku, Web process failed to bind to $PORT within 60 seconds of launch Heroku Web进程在启动后60秒内未能绑定到$ PORT - Heroku Web process failed to bind to $PORT within 60 seconds of launch heroku 和 nodejs 错误(Web 进程未能在启动后 60 秒内绑定到 $PORT) - heroku and nodejs erorr (Web process failed to bind to $PORT within 60 seconds of launch) 尝试将我的 node.js 应用程序上传到 heroku,它说 Web 进程无法在启动后 60 秒内绑定到 $PORT,进程退出,状态为 137 - tried to upload my node.js app to heroku,it says Web process failed to bind to $PORT within 60 seconds of launch, Process exited with status 137 Web进程无法绑定$ port节点 - Web process failed to bind $port node Heroku无法将端口号注入到process.env.PORT - Heroku failed to inject port number to process.env.PORT 尝试将Python /烧瓶应用程序部署到Heroku时无法绑定到$ PORT - Failed to bind to $PORT when trying to deploy Python/flask app to Heroku 解析Cloudcode错误分支需要60秒以上的时间才能返回:为什么? - Parse Cloudcode error branch taking 60seconds+ to return: why? Node.js应用程序不断在Heroku上崩溃,给出错误的启动超时 - Node.js application keeps crashing on Heroku, gives error Boot timeout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM