I am having trouble deploying the angular-seed app (https://github.com/angular/angular-seed) to Heroku. I believe the problem to be that the port number is hard coded into the server starting scripts when heroku needs to dynamically assign the port through the process.env.PORT variable. Looking through the heroku logs confirms that: Starting up http-server, serving ./ on port: 8000
. My Procfile contains web: npm start
, and my package.json file contains
"scripts": {
"prestart": "npm install",
"start": "http-server -a localhost -p 8000"
}
How can I change that so that my server will still work properly in a local dev environment with foreman start
, however dynamically assign a port when using heroku? I want it so that when I type foreman start
on my local dev environment, a server will be created at localhost:8000, but when I deploy the app to heroku, the port will be chosen by Heroku.
I am not a Node developer, but why don't you use the PORT number provisioned by Heroku in your start
script?
ie. "start": "http-server -a localhost -p $PORT"
Then it will run on Heroku. If you're running locally, just export PORT=8000
, or put PORT=8000
in your .env
file if you run using foreman
, and you're good to go.
You can also probably add bash magic to set a PORT if none is set by replacing $PORT
with ${PORT-8000}
.
(Untested)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With