wellyshen / react-cool-starter

😎 🐣 A starter boilerplate for a universal web app with the best development experience and a focus on performance and best practices.
MIT License
1.31k stars 242 forks source link

Run server on custom port #64

Closed ivn-cote closed 7 years ago

ivn-cote commented 7 years ago

So there is a difficulty I struggle with. I'd like to run the project in production mode with a custom port. Right now as I understand I have to change this in the configuration file. But the standard approach is setting environment variables only, like this: PORT=80 yarn start:prod. So maybe I'm missing something. Could you please describe in details how the result application should be deployed? Thanks!

wellyshen commented 7 years ago

@ivn-cote Actually, the PORT is set in packages.json

ivn-cote commented 7 years ago

@wellyshen let me tell you how usually the deployment happens. Automation script grabs the project from a repository (or docker image from a docker repository) and put it in the cloud or on real servers. And usually the port for the service is unstable. It could be very random in some setups (Marathon cluster). As you can imagine, there is no opportunity to paste it in package.json. Service itself should be able to be started with a special configuration setup, including port.

wellyshen commented 7 years ago

@ivn-cote

In packages.json remove the PORT command from start:prod (as the below) and use the command PORT=<your port> yarn start:prod.

    "start:prod": {
      "command": "node ./index.js",
      "env": {
        "NODE_PATH": "./src",
        "NODE_ENV": "production",
        "PORT": 8080 <== Remove it
      }
    },

They're the same result, the different is you pre-define your port through packages.json or dynamic declare it by terminal.