Configuring the React frontend for staging and production
In this section, we are going to change our frontend so that it makes requests to the correct backend APIs in staging and production. At the moment, the REST API has a hardcoded path set to the localhost. We are going to make use of environment variables as we did in our backend, to differentiate between the different environments. Let's open our frontend project in Visual Studio Code and carry out the following steps:
- First, we are going to install a library called
cross-env
that will allow us to set environment variables. Let's execute the following command in the Terminal:> npm install cross-env --save-dev
- Let's add the following scripts in
package.json
to execute staging and production builds:"scripts": { ..., "build": "react-scripts build", "build:production": "cross-env REACT_APP_ENV=production...