cloud_traveler
cloud_traveler

Reputation: 306

change the configuration of an application based on environment setting: Production vs Development

I am using React and Node on Google App Engine (flexible environment) .

I would like to be able to change the configuration of my application based on environment setting: Production vs Development.

In Development I have the following setup: I run my react app in the browser using localhost:5050 and run node app on my localhost:8080 in package.json I use Proxy: "proxy": "http://localhost:8080" API requests use local URLs: "localhost:8080/something"

In Production I have the following setup: no need for proxy; API URLs are: "https://www.example.com/something"

How can I make sure that when I start the apps in localhost, my API requests will use the local domain and that the proxy will be used ? is there a way to configure it via package.json or via some other option ?

Upvotes: 0

Views: 144

Answers (1)

trkaplan
trkaplan

Reputation: 3487

You need to use .env files to specify your API URLs.

If you are using CRA, see the answer given to this question: How to set build .env variables when running create-react-app build script?

If you are using webpack, see this tutorial: Using environment variables in React

P.S. The proxy feature in package.json isn't mean for production as mentioned in this answer Because it is just a development feature.

Upvotes: 2

Related Questions