diff --git a/.env b/.env index a1b211a..dd79ca2 100644 --- a/.env +++ b/.env @@ -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 diff --git a/README.md b/README.md index 21ed95e..2ea347c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/index.js b/src/index.js index af41a6d..7e659e4 100644 --- a/src/index.js +++ b/src/index.js @@ -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 => {