简体   繁体   English

heroku[web.1]:状态从 up 变为 crashed

[英]heroku[web.1]: State changed from up to crashed

this is my command prompt:这是我的命令提示符:

2022-07-10T23:36:17.323791+00:00 heroku[web.1]: Process exited with status 1
2022-07-10T23:36:17.574484+00:00 heroku[web.1]: State changed from up to crashed
2022-07-10T23:36:17.578331+00:00 heroku[web.1]: State changed from crashed to starting
2022-07-10T23:36:19.862639+00:00 heroku[web.1]: Starting process with command `node server`
2022-07-10T23:36:21.568790+00:00 app[web.1]: Server running in development mode on port 52222
2022-07-10T23:36:22.148988+00:00 heroku[web.1]: State changed from starting to up
2022-07-10T23:36:51.593762+00:00 app[web.1]: MongooseServerSelectionError: connection <monitor> to 104.155.184.217:27017 closed
2022-07-10T23:36:51.593769+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:819:32)
2022-07-10T23:36:51.593771+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:378:10
2022-07-10T23:36:51.593773+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
2022-07-10T23:36:51.593773+00:00 app[web.1]: at new Promise (<anonymous>)
2022-07-10T23:36:51.593774+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
2022-07-10T23:36:51.593774+00:00 app[web.1]: at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1223:10)
2022-07-10T23:36:51.593774+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:377:20)
2022-07-10T23:36:51.593775+00:00 app[web.1]: at connectDB (/app/config/db.js:6:37)
2022-07-10T23:36:51.593775+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:10:1)
2022-07-10T23:36:51.593775+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14) {
2022-07-10T23:36:51.593776+00:00 app[web.1]: reason: TopologyDescription {
2022-07-10T23:36:51.593777+00:00 app[web.1]: type: 'ReplicaSetNoPrimary',
2022-07-10T23:36:51.593777+00:00 app[web.1]: servers: Map(3) {
2022-07-10T23:36:51.593778+00:00 app[web.1]: 'ac-eqnecmx-shard-00-00.uqxpgna.mongodb.net:27017' => [ServerDescription],
2022-07-10T23:36:51.593778+00:00 app[web.1]: 'ac-eqnecmx-shard-00-01.uqxpgna.mongodb.net:27017' => [ServerDescription],
2022-07-10T23:36:51.593778+00:00 app[web.1]: 'ac-eqnecmx-shard-00-02.uqxpgna.mongodb.net:27017' => [ServerDescription]
2022-07-10T23:36:51.593779+00:00 app[web.1]: },
2022-07-10T23:36:51.593779+00:00 app[web.1]: stale: false,
2022-07-10T23:36:51.593780+00:00 app[web.1]: compatible: true,
2022-07-10T23:36:51.593780+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2022-07-10T23:36:51.593780+00:00 app[web.1]: localThresholdMS: 15,
2022-07-10T23:36:51.593781+00:00 app[web.1]: setName: 'atlas-qcim0h-shard-0',
2022-07-10T23:36:51.593781+00:00 app[web.1]: logicalSessionTimeoutMinutes: undefined
2022-07-10T23:36:51.593781+00:00 app[web.1]: },
2022-07-10T23:36:51.593781+00:00 app[web.1]: code: undefined
2022-07-10T23:36:51.593781+00:00 app[web.1]: }
2022-07-10T23:36:51.889734+00:00 heroku[web.1]: Process exited with status 1
2022-07-10T23:36:51.942371+00:00 heroku[web.1]: State changed from up to crashed
2022-07-10T23:47:28.294565+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pomoworko.herokuapp.com request_id=f70e80ad-c7f4-475d-b830-1b1cad21a5cc fwd="181.56.0.86" dyno= connect= service= status=503 bytes= protocol=https

this is my code:这是我的代码:

Procfile:档案:

web:node server

.gitignore: .gitignore:

node_modules/

server.js服务器.js

const express = require('express')
const morgan = require('morgan')
const cors = require('cors')
const connectDB = require('./config/db')
const passport = require('passport')
const bodyParser = require('body-parser')
const routes = require('./routes/index')


connectDB()

const app = express()

if(process.env.NODE_ENV === 'development') {
    app.use(morgan('dev'))
}

app.use(cors())
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
app.use(routes)
app.use(passport.initialize())
require('./config/passport')(passport)

const PORT = process.env.PORT || 3000

app.listen(PORT, console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`))

package.json:包.json:

{
  "name": "flutterauth",
  "version": "1.0.0",
  "description": "Authentication system for flutter apps",
  "main": "server.js",
  "scripts": {
    "start": "cross-env NODE_ENV=production node server",
    "dev": "cross-env NODE_ENV=development nodemon server"
  },
  "author": "pomoworko",
  "license": "MIT",
  "dependencies": {
    "bcrypt": "^5.0.1",
    "body-parser": "^1.20.0",
    "connect-mongo": "^4.6.0",
    "cors": "^2.8.5",
    "cross-env": "^7.0.3",
    "express": "^4.18.1",
    "jwt-simple": "^0.5.6",
    "mongoose": "^6.4.4",
    "morgan": "^1.10.0",
    "nodemon": "^2.0.19",
    "passport": "^0.6.0",
    "passport-jwt": "^4.0.0"
  }
}

For now, I got this:现在,我得到了这个:

在此处输入图像描述

If I write on the command prompt: "heroku restart", It works如果我在命令提示符下写:“heroku restart”,它可以工作

在此处输入图像描述

And if I write on the command prompt: "heroku logs --tail", it shows me again, the first image, it doesn't work如果我在命令提示符下写:“heroku logs --tail”,它会再次显示给我,第一张图片,它不起作用

How to fix this error如何修复此错误

Thank you in advance先感谢您

I'm assuming you are using mongodB atlas.我假设您正在使用 mongodB 地图集。 You need to whitelist your IP address.您需要将您的 IP 地址列入白名单。 To do that, head over to your network access tab, and include an IP address 0.0.0.0/0 .为此,请转到您的network access选项卡,并包含一个 IP 地址0.0.0.0/0 This is a wild card IP address that would allow all IP addresses with the correct credentials to access your DB.这是一个通配符 IP 地址,它允许所有具有正确凭据的 IP 地址访问您的数据库。

As such:像这样: 在此处输入图像描述

Note: This whitelists all IP addresses.注意:这会将所有 IP 地址列入白名单。 It's alright when testing.测试的时候没问题。 But when going into production, you might want to whitelist only IP addresses that should have access to the cluster...for security purposes.但是在投入生产时,您可能只想将应该有权访问集群的 IP 地址列入白名单……出于安全目的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM