首页 > 解决方案 > 为什么heroku因code=H10 status 503而崩溃

问题描述

我浪费了 10 个小时尝试将我的 expo react-native 应用程序与 mongodb 和 node js 部署到 heroku。

我仍然得到

heroku crashed with code=H10 status 503

我尝试了所有教程,

我的环境文件:

MONGO_URI=mongodb+srv://admin:admin@lior.rva16.mongodb.net/<dbname>?retryWrites=true&w=majority
JWT_SECRET=LKDSLCXIOZJSIAJ768

我的服务器包 json:

 "scripts": {
"start": "node index.js",
"heroku-postbuild": "yarn run build:prod"
},
"engines": {
"node": "12.18.3"
},

我的档案:

web:node index.js

我的索引服务器:

 const port = process.env.PORT || 3000;
 const mongoURL = process.env.MONGO_URI;
 //db
 mongoose
.connect(mongoURL, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })
 .then(() => console.log("DB Connected"));
  mongoose.connection.on("error", err => {
 console.log(`DB Connection error: ${err.message}`);
 });
  ..........................
    app.listen(port, () => {
console.log(`listening on port ${port}`);
  });

我的完整项目在https://github.com/roeigr7/LIOR

请帮忙..为什么会崩溃?我究竟做错了什么?

我的错误来自 heroku:

    2020-12-20T20:22:10.757245+00:00 app[web.1]: > @ start /app
2020-12-20T20:22:10.757245+00:00 app[web.1]: > expo start
2020-12-20T20:22:10.757245+00:00 app[web.1]: 
2020-12-20T20:22:10.838503+00:00 app[web.1]: This command requires Expo CLI.
2020-12-20T20:22:10.904600+00:00 app[web.1]: Do you want to install it globally [Y/n]? 
2020-12-20T20:23:10.866595+00:00 heroku[router]: at=error code=H10 desc="App 
 crashed" method=GET path="/nextMeet/by/5fac1f65a9e40443ccdf274b" 
 host=liormassage.herokuapp.com request_id=826c87fb-bb0e-4b72-87e5- 
  6225dfd790ca fwd="37.142.10.178" dyno= connect= service= status=503 bytes= protocol=https

标签: react-nativeherokuexpo

解决方案


首先尝试这个https://dev.to/cpclark360/how-to-host-a-restful-node-js-server-with-mongodb-atlas-database-on-heroku-1opl以确保 mongoDB 已连接到 Heroku,然后看看你得到的错误 2020-12-20T20:22:10.838503+00:00 app[web.1]: This command requires Expo CLI


推荐阅读