user6354
user6354

Reputation: 135

React Configuration in multiple deployments

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

Answers (1)

Ramil Garipov
Ramil Garipov

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

Related Questions