0

I develop a ReactJS App with TypeScript that calls an api, there are two global environments (dev and test (not production)) with different URLs, for example:

baseurl for dev environment: https://dev.example.com/

baseurl for test environment: https://test.example.com/

so how can I switch between these URLs according to the current environment

here is a similar issue for react-native : React-native : detect dev or production env

docker and popular DevOps are used in this project (actually I'm not familiar with them, but maybe this information is help).

any suggestions, please Thank you!

Dalal Mansour
  • 197
  • 5
  • 14

1 Answers1

0

In your package.json you can specify a proxy to these API:s by adding e.g.

"proxy": {
  "/api/*": {
    "target": "https://test.example.com/"
  }
}

Which will proxy your request to this host, e.g. if you were to fetch("api/asd"); you would fetch whatever is at https://test.example.com/api/asd.

gqstav
  • 1,984
  • 1
  • 12
  • 18