Skip to content

Commit

Permalink
Updates Process for Flipping API Url Locally
Browse files Browse the repository at this point in the history
Introduces another ENV variable to specify which API URL should be utilize for the backend connection. Currently acts as a soft-override to the configuration when running locally/non-production.
  • Loading branch information
timimsms committed Apr 29, 2020
1 parent 0ec52cc commit e7fbfe0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
REACT_APP_API=DEV
REACT_APP_DEV_API_URL=http://localhost:4000/graphql
REACT_APP_PROD_API_URL=https://geornal-backend.herokuapp.com/graphql
DANGEROUSLY_DISABLE_HOST_CHECK=true
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ This will run the application in development mode, which will ensure the updates

### Running the API

In many cases you will need to also run the Travel Map API alongside this project.
When running the application locally you must connect to a valid API for handling requests. You can either utilize a local backend server or the production website. To toggle between these configurations, update the the following line in your `.env` file:

**To Use Locally Hosted API**

```
REACT_APP_API=DEV
```

**To Use Production Website's API**

```
REACT_APP_API=PROD
```

Please see [travel-map-api](https://github.com/projectunic0rn/travel-map-api) for more information on how to setup and install the API.

Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ if (localStorage.getItem("token")) {
}

let clientUrl = "";
if (process.env.NODE_ENV === "production") {
if (process.env.NODE_ENV === "production" || process.env.REACT_APP_API === "PROD") {
clientUrl = process.env.REACT_APP_PROD_API_URL;
} else if (process.env.REACT_APP_TEST_API_URL != null) {
clientUrl = process.env.REACT_APP_TEST_API_URL;
} else {
} else if (process.env.REACT_APP_API === "DEV") {
clientUrl = process.env.REACT_APP_DEV_API_URL;
}

const client = new ApolloClient({
uri: clientUrl,
request: async operation => {
Expand Down

0 comments on commit e7fbfe0

Please sign in to comment.