Heroku无法启动我的app.js(代码H10状态503)

时间:2020-06-15 10:55:38

标签: javascript node.js mongodb heroku

让我从屏幕快照开始。

enter image description here

enter image description here

enter image description here

enter image description here

这里有完整的错误日志

    2020-06-15T10:46:45.640400+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-15T10:46:47.833544+00:00 app[web.1]: 
2020-06-15T10:46:47.833563+00:00 app[web.1]: > learn-blog@1.0.0 start /app
2020-06-15T10:46:47.833563+00:00 app[web.1]: > node app.js
2020-06-15T10:46:47.833563+00:00 app[web.1]: 
2020-06-15T10:47:22.069169+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-06-15T10:47:22.069203+00:00 app[web.1]:     at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:826:32)
2020-06-15T10:47:22.069204+00:00 app[web.1]:     at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:335:15)
2020-06-15T10:47:22.069204+00:00 app[web.1]:     at run (/app/app_server/server/server.js:26:20)
2020-06-15T10:47:22.069204+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:3:1)
2020-06-15T10:47:22.069205+00:00 app[web.1]:     at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-06-15T10:47:22.069205+00:00 app[web.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-06-15T10:47:22.069205+00:00 app[web.1]:     at Module.load (internal/modules/cjs/loader.js:986:32)
2020-06-15T10:47:22.069205+00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-06-15T10:47:22.069206+00:00 app[web.1]:     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
2020-06-15T10:47:22.069206+00:00 app[web.1]:     at internal/main/run_main_module.js:17:47 {
2020-06-15T10:47:22.069207+00:00 app[web.1]:   reason: TopologyDescription {
2020-06-15T10:47:22.069207+00:00 app[web.1]:     type: 'ReplicaSetNoPrimary',
2020-06-15T10:47:22.069207+00:00 app[web.1]:     setName: null,
2020-06-15T10:47:22.069207+00:00 app[web.1]:     maxSetVersion: null,
2020-06-15T10:47:22.069207+00:00 app[web.1]:     maxElectionId: null,
2020-06-15T10:47:22.069208+00:00 app[web.1]:     servers: Map {
2020-06-15T10:47:22.069208+00:00 app[web.1]:       'learningcluster-shard-00-01-izdfm.mongodb.net:27017' => [ServerDescription],
2020-06-15T10:47:22.069208+00:00 app[web.1]:       'learningcluster-shard-00-02-izdfm.mongodb.net:27017' => [ServerDescription],
2020-06-15T10:47:22.069208+00:00 app[web.1]:       'learningcluster-shard-00-00-izdfm.mongodb.net:27017' => [ServerDescription]
2020-06-15T10:47:22.069209+00:00 app[web.1]:     },
2020-06-15T10:47:22.069209+00:00 app[web.1]:     stale: false,
2020-06-15T10:47:22.069209+00:00 app[web.1]:     compatible: true,
2020-06-15T10:47:22.069210+00:00 app[web.1]:     compatibilityError: null,
2020-06-15T10:47:22.069210+00:00 app[web.1]:     logicalSessionTimeoutMinutes: null,
2020-06-15T10:47:22.069210+00:00 app[web.1]:     heartbeatFrequencyMS: 10000,
2020-06-15T10:47:22.069210+00:00 app[web.1]:     localThresholdMS: 15,
2020-06-15T10:47:22.069210+00:00 app[web.1]:     commonWireVersion: null
2020-06-15T10:47:22.069211+00:00 app[web.1]:   }
2020-06-15T10:47:22.069211+00:00 app[web.1]: }
2020-06-15T10:47:22.143281+00:00 heroku[web.1]: Process exited with status 0
2020-06-15T10:47:22.184007+00:00 heroku[web.1]: State changed from starting to crashed
2020-06-15T10:48:10.737182+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=morning-taiga-29926.herokuapp.com request_id=840ea8ca-9d88-451d-9720-77cbafc687c0 fwd="88.238.178.195" dyno= connect= service= status=503 bytes= protocol=https
2020-06-15T10:48:11.205261+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=morning-taiga-29926.herokuapp.com request_id=2f1efa47-f83b-4d52-8d1c-2a7e45e7b666 fwd="88.238.178.195" dyno= connect= service= status=503 bytes= protocol=https

我检查了我的mongodb Atlas群集,我的IP地址在白名单中。另外,我尝试将网络访问权限设置为0.0.0.0/0,但是它也没有起作用...

在我的本地地址(8080)中,一切正常。

1 个答案:

答案 0 :(得分:0)

我修复了。

enter image description here

我在代码中添加了这些内容;

mongoose.Promise = global.Promise;

...

const PORT = process.env.PORT || 8080;    
const CONNECTION_URI = process.env.MONGODB_URI || 'mongodb+srv://learnBlogAdmin:learnBlogAdminsPowsyetmiş22a@learningcluster-izdfm.mongodb.net/personalblog?retryWrites=true&w=majority';

...

run()
    .then(() => {
        console.log("IT WORKS");
    })
    .catch((err) => {
        console.log(err);
        throw err;
    })

它起作用了。