Skip to content

Commit

Permalink
Add Netlify configuration for Test Deploy Previews (#356)
Browse files Browse the repository at this point in the history
We need the ability to swap API url depending
on where the UI is deployed. If deployed as a development
build, it needs to point to the testing instance.

Add 'dotenv' dependency to pass API URL depending on environment
to production build script and configure Netlify to accurately
build proper build depending on which branch it's deploying.
  • Loading branch information
StormFireFox1 authored Oct 19, 2020
1 parent 16805c5 commit 90293ce
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_API_URL=https://acmucsd-portal-testing.herokuapp.com
PORT=8080
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_API_URL=https://acmucsd-membership-portal-api.herokuapp.com
13 changes: 13 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
[build]
# Configure it so that deploy previews and `nightly` run on the testing instance, not
# on the default instance
[context.deploy-preview]
publish = "build/"
command = "CI=false npm run build:dev"
[context.deploy-preview.environment]
NODE_ENV = "development"
[context.branch-deploy]
command = "CI=false npm run build:dev"
[context.branch-deploy.environment]
NODE_ENV = "development"

# The following redirect is intended for use with most SPAs that handle
# routing internally.
[[redirects]]
Expand Down
61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
"yup": "^0.29.3"
},
"scripts": {
"build": "react-app-rewired build",
"build:dev": "dotenv -e .env.development react-app-rewired build",
"build": "dotenv -e .env.production react-app-rewired build",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
"eject": "react-scripts eject",
"lint": "eslint \"**/*.{ts,tsx}\" && npx stylelint \"**/*.less\"",
"lint:fix": "eslint \"**/*.{ts,tsx}\" --fix && npx stylelint \"**/*.less\" --fix",
"start": "cross-env PORT=8080 react-app-rewired start",
"start": "dotenv -e .env.development react-app-rewired start",
"test": "jest",
"test:watch": "jest --watch"
},
Expand Down Expand Up @@ -76,6 +77,7 @@
"babel-jest": "^24.8.0",
"coveralls": "^3.0.6",
"cross-env": "^7.0.2",
"dotenv-cli": "^4.0.0",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-to-json": "^3.4.0",
Expand Down
5 changes: 1 addition & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
let apiurl = 'https://acmucsd-membership-portal-api.herokuapp.com';
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
apiurl = 'https://acmucsd-portal-testing.herokuapp.com';
}
const apiurl = process.env.REACT_APP_API_URL;

export default {
API_URL: apiurl,
Expand Down

0 comments on commit 90293ce

Please sign in to comment.