微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误 R10启动超时-> Web 进程未能在 Heroku 中启动后 60 秒内绑定到 $PORT

如何解决错误 R10启动超时-> Web 进程未能在 Heroku 中启动后 60 秒内绑定到 $PORT

问题

我正在尝试在 heroku 中托管我的 MERN 堆栈应用程序并反复收到此错误。我无法理解导致问题的原因

heroku logs --tail 获取的构建日志

2021-04-19T10:48:00.000000+00:00 app[api]: Build started by user soumalyabhattacharya6@gmail.com
2021-04-19T10:50:15.718383+00:00 heroku[web.1]: State changed from crashed to starting
2021-04-19T10:50:15.442857+00:00 app[api]: Release v8 created by user soumalyabhattacharya6@gmail.com
2021-04-19T10:50:15.442857+00:00 app[api]: Deploy b1f9e6f1 by user soumalyabhattacharya6@gmail.com
2021-04-19T10:50:15.000000+00:00 app[api]: Build succeeded
2021-04-19T10:50:34.808498+00:00 heroku[web.1]: Starting process with command `npm start`
2021-04-19T10:50:39.377743+00:00 app[web.1]:
2021-04-19T10:50:39.377769+00:00 app[web.1]: > protium@1.0.0 start /app
2021-04-19T10:50:39.377770+00:00 app[web.1]: > node index.js
2021-04-19T10:50:39.377770+00:00 app[web.1]:
2021-04-19T10:50:39.664885+00:00 app[web.1]: Server running on port: 5000
2021-04-19T10:51:35.368111+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process Failed to bind to $PORT within 60 seconds of launch
2021-04-19T10:51:35.549055+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-04-19T10:51:35.775090+00:00 heroku[web.1]: Process exited with status 137
2021-04-19T10:51:35.875892+00:00 heroku[web.1]: State changed from starting to crashed

我的项目结构是

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        19-04-2021  11:23 AM                FrontEnd
d-----        19-04-2021  01:36 PM                node_modules
-a----        19-04-2021  02:22 PM              0 .env
-a----        19-04-2021  02:27 PM            527 .gitignore
-a----        19-04-2021  04:17 PM            975 index.js
-a----        19-04-2021  02:22 PM          23373 package-lock.json
-a----        19-04-2021  04:42 PM            763 package.json
-a----        19-04-2021  02:45 PM             14 procfile

FrontEnd 中有一个使用 create-react-app 创建的简单 React 应用。

我的 index.js 文件如下所示:

require("dotenv").config();
const express = require('express');
const path =  require('path');
const app = express();
const port = process.env.port || 5000;
app.use(express.json());
app.use(express.urlencoded({extended: true}));

app.get("/",(req,res)=>{
    res.json({'messege': "Welcome to Backend of Protium"});
});
app.get('/api/hello',res) => {
  res.send({ express: 'Hello From Express' });
});
app.post('/api/world',res) => {
  res.send(
    `I received your POST request. This is what you sent me: ${req.body.post}`,);
});
if (process.env.NODE_ENV === 'production') {
    // Serve any static files
    app.use(express.static(path.join(__dirname,'FrontEnd/build')));
    // Handle React routing,return all requests to React app
    app.get('*',function(req,res) {
      res.sendFile(path.join(__dirname,'FrontEnd/build','index.html'));
    });
  }
app.listen(port,()=>{console.log(`Server running on port: ${port}`)});

我的 root-directory package.json 文件如下所示:

    {
      "name": "protium","version": "1.0.0","description": "Project Management Platfrom Backend","main": "index.js","dependencies": {
        "dotenv": "^8.2.0","express": "^4.17.1","jsonwebtoken": "^8.5.1","mongodb": "^3.6.6","node-fetch": "^2.6.1"
      },"scripts": {
        "test": "echo \"Error: no test specified\" && exit 1","start": "node index.js","postinstall": "cd FrontEnd && npm install && npm run build"
        
      },"repository": {
        "type": "git","url": "git+https://github.com/soumalyatheking22012001/Protium-Backend.git"
      },"author": "Soumalya Bhattacharya","license": "ISC","bugs": {
        "url": "https://github.com/soumalyatheking22012001/Protium-Backend/issues"
      }
    }

package.jsonroot/FrontEnd 看起来像这样:

{
  "name": "protium","version": "0.1.0","description": "Project Management Platfrom Frontend","private": true,"dependencies": {
    "@material-ui/core": "^4.11.3","@material-ui/icons": "^4.11.2","@n8tb1t/use-scroll-position": "^2.0.3","react": "^17.0.2","react-dom": "^17.0.2","react-router-dom": "^5.2.0","react-scripts": "4.0.3","sass": "^1.32.8","swiper": "^6.5.6","web-vitals": "^1.0.1"
  },"devDependencies": {
    "@testing-library/jest-dom": "^5.11.4","@testing-library/react": "^11.1.0","@testing-library/user-event": "^12.1.10"
  },"repository": {
    "type": "git","url": "https://github.com/soumalyatheking22012001/Protium-Frontend.git"
  },"scripts": {
    "start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
  },"bugs": {
    "url": "https://github.com/soumalyatheking22012001/Protium-Frontend.git/issues"
  },"eslintConfig": {
    "extends": [
      "react-app","react-app/jest"
    ]
  },"browserslist": {
    "production": [
      ">0.2%","not dead","not op_mini all"
    ],"development": [
      "last 1 chrome version","last 1 firefox version","last 1 safari version"
    ]
  },"proxy": "0.0.0.0"
}

我还没有实现任何从前端到后端的 API 调用

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。