Heroku错误:heroku [路由器]:at =错误代码= H10 desc =“应用程序崩溃”方法=获取路径=“ /”?

时间:2020-10-22 03:37:57

标签: node.js heroku heroku-api

我正在尝试在Heroku上部署非常简单的Nodejs API,但是我似乎无法弄清为什么它一直给我这个错误。即使使用heroku local web,该应用程序也可以在本地服务器上正常运行。我的应用程序正在app.listen( process.env.PORT || 5500 );上监听。

这是我的错误 heroku logs --tail

2020-10-22T03:09:40.912659+00:00 app[web.1]: 'cluster0-shard-00-01.4mqda.mongodb.net:27017' => [ServerDescription]
2020-10-22T03:09:40.912659+00:00 app[web.1]: },
2020-10-22T03:09:40.912659+00:00 app[web.1]: stale: false,
2020-10-22T03:09:40.912660+00:00 app[web.1]: compatible: true,
2020-10-22T03:09:40.912660+00:00 app[web.1]: compatibilityError: null,
2020-10-22T03:09:40.912660+00:00 app[web.1]: logicalSessionTimeoutMinutes: null,
2020-10-22T03:09:40.912660+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2020-10-22T03:09:40.912661+00:00 app[web.1]: localThresholdMS: 15,
2020-10-22T03:09:40.912661+00:00 app[web.1]: commonWireVersion: null
2020-10-22T03:09:40.912661+00:00 app[web.1]: }
2020-10-22T03:09:40.912662+00:00 app[web.1]: }
2020-10-22T03:09:41.093698+00:00 heroku[web.1]: Process exited with status 0
2020-10-22T03:09:46.165964+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-22T03:09:46.168346+00:00 heroku[web.1]: State changed from crashed to starting
2020-10-22T03:09:49.527931+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-10-22T03:10:23.122929+00:00 app[web.1]: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
2020-10-22T03:10:23.123001+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:800:32)
2020-10-22T03:10:23.123006+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-10-22T03:10:23.123010+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
2020-10-22T03:10:23.123015+00:00 app[web.1]: at new Promise (<anonymous>)
2020-10-22T03:10:23.123019+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
2020-10-22T03:10:23.123020+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-10-22T03:10:23.123020+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:14:10)
2020-10-22T03:10:23.123020+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1200:30)
2020-10-22T03:10:23.123020+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
2020-10-22T03:10:23.123021+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1049:32)
2020-10-22T03:10:23.123021+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:937:14)
2020-10-22T03:10:23.123021+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
2020-10-22T03:10:23.123022+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 {
2020-10-22T03:10:23.123026+00:00 app[web.1]: reason: TopologyDescription {
2020-10-22T03:10:23.123026+00:00 app[web.1]: type: 'ReplicaSetNoPrimary',
2020-10-22T03:10:23.123026+00:00 app[web.1]: setName: null,
2020-10-22T03:10:23.123027+00:00 app[web.1]: maxSetVersion: null,
2020-10-22T03:10:23.123027+00:00 app[web.1]: maxElectionId: null,
2020-10-22T03:10:23.123027+00:00 app[web.1]: servers: Map(3) {
2020-10-22T03:10:23.123027+00:00 app[web.1]: 'cluster0-shard-00-02.4mqda.mongodb.net:27017' => [ServerDescription],
2020-10-22T03:10:23.123028+00:00 app[web.1]: 'cluster0-shard-00-00.4mqda.mongodb.net:27017' => [ServerDescription],
2020-10-22T03:10:23.123028+00:00 app[web.1]: 'cluster0-shard-00-01.4mqda.mongodb.net:27017' => [ServerDescription]
2020-10-22T03:10:23.123033+00:00 app[web.1]: },
2020-10-22T03:10:23.123033+00:00 app[web.1]: stale: false,
2020-10-22T03:10:23.123033+00:00 app[web.1]: compatible: true,
2020-10-22T03:10:23.123033+00:00 app[web.1]: compatibilityError: null,
2020-10-22T03:10:23.123034+00:00 app[web.1]: logicalSessionTimeoutMinutes: null,
2020-10-22T03:10:23.123034+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2020-10-22T03:10:23.123034+00:00 app[web.1]: localThresholdMS: 15,
2020-10-22T03:10:23.123034+00:00 app[web.1]: commonWireVersion: null
2020-10-22T03:10:23.123035+00:00 app[web.1]: }
2020-10-22T03:10:23.123035+00:00 app[web.1]: }
2020-10-22T03:10:23.187310+00:00 heroku[web.1]: Process exited with status 0
2020-10-22T03:10:23.226782+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-22T03:10:24.274124+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=adak.herokuapp.com request_id=2e574211-23f3-423c-8322-2ec071a7f798 fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T03:10:25.104524+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/app" host=adak.herokuapp.com request_id=53362476-b37c-487e-9453-0cce7aa0033d fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T03:10:25.478442+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=adak.herokuapp.com request_id=a8c9df8f-4bfc-44a8-8061-ce6e0950f431 fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T03:10:26.329468+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=adak.herokuapp.com request_id=8d56ea2d-257c-4118-9451-b454e59651f7 fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T03:10:30.517993+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/app" host=adak.herokuapp.com request_id=8ae82052-e3d2-410c-90ed-e92e522acdeb fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T03:10:30.857187+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=adak.herokuapp.com request_id=ff3b48e6-6712-4ab8-8937-07b0329fb97c fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T03:13:50.120474+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=adak.herokuapp.com request_id=a94ad607-4349-44be-af8d-14d8cb31a497 fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T03:13:50.386222+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=adak.herokuapp.com request_id=596442ac-c410-4c21-ab4b-fba6a358215f fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https
2020-10-22T03:14:25.000000+00:00 app[api]: Build started by user kevinmnm2010@gmail.com
2020-10-22T03:14:46.000000+00:00 app[api]: Build succeeded
2020-10-22T03:14:46.007993+00:00 app[api]: Deploy e8565aab by user kevinmnm2010@gmail.com
2020-10-22T03:14:46.007993+00:00 app[api]: Release v4 created by user kevinmnm2010@gmail.com
2020-10-22T03:14:46.201472+00:00 heroku[web.1]: State changed from crashed to starting
2020-10-22T03:14:48.884957+00:00 heroku[web.1]: Starting process with command `node index.js`
2020-10-22T03:15:21.469714+00:00 app[web.1]: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
2020-10-22T03:15:21.477855+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:800:32)
2020-10-22T03:15:21.477862+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:342:10
2020-10-22T03:15:21.477867+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
2020-10-22T03:15:21.477871+00:00 app[web.1]: at new Promise (<anonymous>)
2020-10-22T03:15:21.477876+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
2020-10-22T03:15:21.477876+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:341:10)
2020-10-22T03:15:21.477876+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:14:10)
2020-10-22T03:15:21.477877+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1200:30)
2020-10-22T03:15:21.477877+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
2020-10-22T03:15:21.477877+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1049:32)
2020-10-22T03:15:21.477878+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:937:14)
2020-10-22T03:15:21.477878+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
2020-10-22T03:15:21.477878+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 {
2020-10-22T03:15:21.477884+00:00 app[web.1]: reason: TopologyDescription {
2020-10-22T03:15:21.477884+00:00 app[web.1]: type: 'ReplicaSetNoPrimary',
2020-10-22T03:15:21.477884+00:00 app[web.1]: setName: null,
2020-10-22T03:15:21.477885+00:00 app[web.1]: maxSetVersion: null,
2020-10-22T03:15:21.477885+00:00 app[web.1]: maxElectionId: null,
2020-10-22T03:15:21.477885+00:00 app[web.1]: servers: Map(3) {
2020-10-22T03:15:21.477886+00:00 app[web.1]: 'cluster0-shard-00-02.4mqda.mongodb.net:27017' => [ServerDescription],
2020-10-22T03:15:21.477886+00:00 app[web.1]: 'cluster0-shard-00-00.4mqda.mongodb.net:27017' => [ServerDescription],
2020-10-22T03:15:21.477886+00:00 app[web.1]: 'cluster0-shard-00-01.4mqda.mongodb.net:27017' => [ServerDescription]
2020-10-22T03:15:21.477891+00:00 app[web.1]: },
2020-10-22T03:15:21.477877+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1200:30)
2020-10-22T03:15:21.477877+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
2020-10-22T03:15:21.477877+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1049:32)
2020-10-22T03:15:21.477878+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:937:14)
2020-10-22T03:15:21.477878+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
2020-10-22T03:15:21.477878+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 {
2020-10-22T03:15:21.477884+00:00 app[web.1]: reason: TopologyDescription {
2020-10-22T03:15:21.477884+00:00 app[web.1]: type: 'ReplicaSetNoPrimary',
2020-10-22T03:15:21.477884+00:00 app[web.1]: setName: null,
2020-10-22T03:15:21.477885+00:00 app[web.1]: maxSetVersion: null,
2020-10-22T03:15:21.477885+00:00 app[web.1]: maxElectionId: null,
2020-10-22T03:15:21.477885+00:00 app[web.1]: servers: Map(3) {
2020-10-22T03:15:21.477886+00:00 app[web.1]: 'cluster0-shard-00-02.4mqda.mongodb.net:27017' => [ServerDescription],
2020-10-22T03:15:21.477886+00:00 app[web.1]: 'cluster0-shard-00-00.4mqda.mongodb.net:27017' => [ServerDescription],
2020-10-22T03:15:21.477886+00:00 app[web.1]: 'cluster0-shard-00-01.4mqda.mongodb.net:27017' => [ServerDescription]
2020-10-22T03:15:21.477891+00:00 app[web.1]: },
2020-10-22T03:15:21.477892+00:00 app[web.1]: stale: false,
2020-10-22T03:15:21.477892+00:00 app[web.1]: compatible: true,
2020-10-22T03:15:21.477892+00:00 app[web.1]: compatibilityError: null,
2020-10-22T03:15:21.477893+00:00 app[web.1]: logicalSessionTimeoutMinutes: null,
2020-10-22T03:15:21.477893+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2020-10-22T03:15:21.477893+00:00 app[web.1]: localThresholdMS: 15,
2020-10-22T03:15:21.477893+00:00 app[web.1]: commonWireVersion: null
2020-10-22T03:15:21.477894+00:00 app[web.1]: }
2020-10-22T03:15:21.477894+00:00 app[web.1]: }
2020-10-22T03:15:21.561613+00:00 heroku[web.1]: Process exited with status 0
2020-10-22T03:15:21.656462+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-22T03:15:23.967387+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=adak.herokuapp.com request_id=fe070797-e414-40c8-aeac-957b78fec27b fwd="98.219.228.15" dyno= connect= service= status=503 bytes= protocol=https

在浏览器控制台上出现错误: enter image description here

Procfile:

web: node index.js

package.json

{
  "name": "adak-v3-server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "engines": {
    "node": "14.3.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "author": "",
  "license": "MIT",
  "dependencies": {
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
    "mongodb": "^3.6.2",
    "mongoose": "^5.10.9",
    "serve": "^11.3.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.6"
  }
}

我想念什么?我已经尝试了很多在Stackoverflow上冲浪的方法,但没有任何帮助:(

1 个答案:

答案 0 :(得分:1)

使用以下代码进行连接-

mongoose.connect(uri, {
      useNewUrlParser: true,
      useCreateIndex: true,
      useUnifiedTopology: true
    }).then(res=>{
            console.log("DB Connected!")
    }).catch(err => {
      console.log(Error, err.message);
    })

如果使用上面的代码-
您需要将进入MongoDB Atlas的heroku IP地址b列入白名单。
要添加的IP地址--'0.0.0.0/0'