Skip to content

Commit

Permalink
Merge pull request gothinkster#56 from deksden/fix-default-port
Browse files Browse the repository at this point in the history
Use cross-env to change default port
  • Loading branch information
EricSimons authored May 4, 2017
2 parents 16e498f + b899d4a commit 69860f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ To get the frontend running locally:
- `npm install` to install all req'd dependencies
- `npm start` to start the local server (this project uses create-react-app)

Local web server will use port 4100 instead of standard React's port 3000 to prevent conflicts with some backends like Node or Rails. You can configure port in scripts section of `package.json`: we use [cross-env](https://github.com/kentcdodds/cross-env) to set environment variable PORT for React scripts, this is Windows-compatible way of setting environment variables.

Alternatively, you can add `.env` file in the root folder of project to set environment variables (use PORT to change webserver's port). This file will be ignored by git, so it is suitable for API keys and other sensitive stuff. Refer to [dotenv](https://github.com/motdotla/dotenv) and [React](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-development-environment-variables-in-env) documentation for more details. Also, please remove setting variable via script section of `package.json` - `dotenv` never override variables if they are already set.

### Making requests to the backend API

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"cross-env": "^4.0.0",
"react-scripts": "0.8.5"
},
"dependencies": {
Expand All @@ -18,9 +19,9 @@
"superagent-promise": "^1.1.0"
},
"scripts": {
"start": "react-scripts start",
"start": "cross-env PORT=4100 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"test": "cross-env PORT=4100 react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}

0 comments on commit 69860f1

Please sign in to comment.