I have a MERN stack built using Facebook's Create-React-App template and Nodejs/Express that produces errors when deployed. I am using Heroku's Nodejs Buildpack
At first, when I deployed it after configuring my proxy for localhost, my app would only display "Invalid Host Header". FB's docs and a Github Issue recommended specifying the host and even dangerously disabling host check; I did both of these, and error #1 was gone but #2 arose even with my .env.development file with
HOST=my-heroku-app.herokuapp.com
(is this wrong?). (I also tried ejecting so I could disable host check manually as described here but this also brought me to my next error.)Now I just got a Heroku application error, with the following log:
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
Here's my code for setting up the server
const port = process.env.PORT || 3001; //starts the server and listens for requests app.listen(port, function () { debug(`api running on port ${port}`); });
I've tried changing the port and host as suggested here with no luck.
What can I do to resolve this error in heroku? Let me know if I should provide any additional information. Thanks.
EDIT: 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"
}
}