O
O
Oleg2020-07-01 18:49:42
JavaScript
Oleg, 2020-07-01 18:49:42

How to change the domain for sending back requests depending on the deployment?

My react application is on gitlab and 2 deployments are configured through gitlab-ci: on dev (for developers and testers) and preprod (for customers). Looks like this .

At the same time, webpack is very minimalistic, here it is .

And the server is simple on the node .

Now the front is making back requests for one domain. Approximately like this:

const BASE_URL = 'https://account.b2b-staging.kpb.lt/account'

const result = axios({
  method: 'GET',
  url: `${BASE_URL}/users`
})


So, I need the BASE_URL to be different depending on where it is being deployed, to dev or to preprod.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil, 2020-07-01
@TchernyavskD

There are many options. You can, for example, use the define plugin in the webpack in the dev and prod assembly. In fact, depending on env, you will have your own config for the desired version

N
Nick, 2020-07-01
@DragonSpirit

as an option to store in .env files as environment variables
https://github.com/motdotla/dotenv

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question