0

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 ?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.