使用Create-React-App和Node / Express部署到Heroku:EADDRNOTAVAIL

时间:2018-03-04 03:45:42

标签: node.js reactjs express heroku create-react-app

我使用Facebook的Create-React-App模板和Nodejs / Express构建了MERN堆栈,在部署时会产生错误。我正在使用Heroku's Nodejs Buildpack

  1. 首先,当我在为localhost配置代理后部署它时,我的应用程序只会显示“无效的主机标头”。 FB's docsa Github Issue建议指定主机,甚至危险地禁用主机检查;我做了这两个,错误#1消失了但是#2出现了我的.env.development文件HOST=my-heroku-app.herokuapp.com(这是错误的吗?)。 (我也尝试ejecting,因此我可以手动禁用主机检查as described here,但这也让我遇到了下一个错误。)

  2. 现在我刚收到一个Heroku应用程序错误,其中包含以下日志:

    2018-03-04T03:02:49.270931+00:00 heroku[web.1]: - Restarting
    2018-03-04T03:02:49.271285+00:00 heroku[web.1]: - State changed from up to starting
    2018-03-04T03:02:04.000000+00:00 app[api]: - Build succeeded
    2018-03-04T03:02:50.294779+00:00 heroku[web.1]: - Stopping all processes with SIGTERM
    2018-03-04T03:02:50.404316+00:00 heroku[web.1]: - Process exited with status 143
    2018-03-04T03:02:57.240490+00:00 heroku[web.1]: - Starting process with command `react-scripts start`
    2018-03-04T03:03:01.011562+00:00 heroku[web.1]: - Process exited with status 1
    2018-03-04T03:03:01.038935+00:00 heroku[web.1]: - State changed from starting to crashed
    2018-03-04T03:03:01.040756+00:00 heroku[web.1]: - State changed from crashed to starting
    2018-03-04T03:03:00.918201+00:00 app[web.1]: - Could not find an open port at myapp.herokuapp.com.
    2018-03-04T03:03:00.918218+00:00 app[web.1]: - Network error message: listen EADDRNOTAVAIL 54.235.183.213
    2018-03-04T03:03:11.873080+00:00 heroku[web.1]: - State changed from starting to crashed
    2018-03-04T03:03:11.856257+00:00 heroku[web.1]: - Process exited with status 1
    2018-03-04T03:03:14.126300+00:00 heroku[router]: - at=error code=H10 desc="App crashed" method=GET path="/" host=mysite.herokuapp.com request_id=a688b1cb-d756-4201-a056-25d65ad13de1 fwd="ip_of_my_site" dyno= connect= service= status=503 bytes= protocol=https
    

    这是我设置服务器的代码

    const port = process.env.PORT || 3001;
    //starts the server and listens for requests
    app.listen(port, function () {
        debug(`api running on port ${port}`);
    });
    
  3. 我已按照此处的建议尝试changing the port and host但没有运气。

    如何在heroku中解决此错误?如果我应该提供任何其他信息,请告诉我。感谢。

    编辑:package.json

    {
      "name": "my_project",
      "version": "0.1.0",
      "private": true,
      "proxy": "http://localhost:3001/",
      "dependencies": {
        "@sendgrid/mail": "^6.2.1",
        "async": "^2.6.0",
        "aws-sdk": "^2.205.0",
        "axios": "^0.14.0",
        "body-parser": "~1.17.1",
        "cookie-parser": "~1.4.3",
        "cors": "^2.8.4",
        "debug": "^2.6.9",
        "dotenv": "^5.0.1",
        "express": "~4.15.2",
        "express-fileupload": "^0.4.0",
        "font-awesome": "^4.7.0",
        "foreman": "^2.0.0",
        "history": "^4.7.2",
        "marked": "^0.3.17",
        "milligram": "^1.3.0",
        "milligram-react": "0.0.0",
        "mongodb": "^2.2.35",
        "mongoose": "^4.13.11",
        "morgan": "~1.8.1",
        "nodemailer": "^4.6.0",
        "nodemon": "^1.17.1",
        "react": "^16.2.0",
        "react-bootstrap": "^0.32.1",
        "react-dom": "^16.2.0",
        "react-fontawesome": "^1.6.1",
        "react-icons": "^2.2.7",
        "react-onclickoutside": "^6.7.1",
        "react-router": "^4.2.0",
        "react-router-dom": "^4.2.2",
        "react-scripts": "1.0.17",
        "react-table": "^6.8.0",
        "sendgrid-web": "0.0.5",
        "serve-favicon": "~2.4.2",
        "supports-color": "^5.3.0"
      },
      "scripts": {
        "start": "react-scripts start | node server.js",
        "start-dev": "set DEBUG=* & nodemon server.js",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      }
    }
    

0 个答案:

没有答案