Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Seperate ports for production and dev #65

Merged
merged 3 commits into from
Jan 4, 2016
Merged

Seperate ports for production and dev #65

merged 3 commits into from
Jan 4, 2016

Conversation

gauntface
Copy link

As per #64 idea, PR to do exactly that.

I've avoided a random port for dev server simply because nodemon will restart the server and having a random port assigned each time sounds like a pain to me.

cc @addyosmani @jeffposnick

const PROD_PORT = 8080;
const DEV_PORT = 8081;
// This results in different ports for prod and dev
var port = (GLOBAL.config.env === 'prod') ? PROD_PORT : DEV_PORT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't very clear in #64 (comment)

Some hosting providers (at least Heroku and App Engine, though it's probably more than those) require that your Node.js server listens on whatever they set process.env.PORT to. I think they want the flexibility to start up your process on whatever port they choose, based on whatever restrictions they have in place.

So what I'd suggest is to always use process.env.PORT if it's already set, and if it's not set, then use one port number for 'prod' and a separate port number for 'dev'.

Maybe something like var port = process.env.PORT || ((GLOBAL.config.env === 'prod') ? PROD_PORT : DEV_PORT);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this only applies to the gulp build. If heroku where to start the server, it would be starting node app.js presumably on a prebuilt version of the front end.

From this app.js would use process.env.PORT - i.e. what ever heroku set.

The scenario I haven't accounted for is if the process.env.PORT is defined although running node app.js will select a random port (or so it seems).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. 👍

@gauntface
Copy link
Author

@jeffposnick Had a think on this and made a few small tweaks.

1.) Ports are defined in the gulpfile.js now (easier and more obvious where to set these).
1.) Error check the port number so that if it's not set or set incorrectly the port is set to 0, which means it will be assigned a random available port.

cc @addyosmani

@jeffposnick
Copy link
Contributor

👍

gauntface pushed a commit that referenced this pull request Jan 4, 2016
Seperate ports for production and dev
@gauntface gauntface merged commit 7fea1a7 into master Jan 4, 2016
@gauntface gauntface deleted the prod-dev-ports branch January 20, 2016 11:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants