Reputation: 135
We want to deploy the same react web app on our data center and in the cloud. Each deployment has different settings like the base url the API is located and other configurations. Which is the best way to inject this info? At building time? Is there a file like web.config in .net but for react apps?
Upvotes: 0
Views: 415
Reputation: 473
If you use create-react-app, you can use Environment Variables.
Just define variables in your CI and use it like this:
const API_HOST = process.env.REACT_APP_API_HOST;
You also able to define it inside the .env file like this:
REACT_APP_API_HOST = my-api-path.com
Upvotes: 1