簡體   English   中英

heroku[web.1]:狀態從 up 變為 crashed

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

這是我的命令提示符:

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

這是我的代碼:

檔案:

web:node server

.gitignore:

node_modules/

服務器.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}`))

包.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"
  }
}

現在,我得到了這個:

在此處輸入圖像描述

如果我在命令提示符下寫:“heroku restart”,它可以工作

在此處輸入圖像描述

如果我在命令提示符下寫:“heroku logs --tail”,它會再次顯示給我,第一張圖片,它不起作用

如何修復此錯誤

先感謝您

我假設您正在使用 mongodB 地圖集。 您需要將您的 IP 地址列入白名單。 為此,請轉到您的network access選項卡,並包含一個 IP 地址0.0.0.0/0 這是一個通配符 IP 地址,它允許所有具有正確憑據的 IP 地址訪問您的數據庫。

像這樣: 在此處輸入圖像描述

注意:這會將所有 IP 地址列入白名單。 測試的時候沒問題。 但是在投入生產時,您可能只想將應該有權訪問集群的 IP 地址列入白名單……出於安全目的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM