Arar
Arar

Reputation: 2066

Configure rest url in react application for different environment

Building a react application that consumes a rest api.

  1. How can we configure the rest api url based on the environment (local/dev/qa/prod)?
  2. The rest API url might change every-time we deploy the application to AWS (Link gets generated in AWS API Gateway), Have we have to manually update the url list in the react app? Do we have a way to sync these urls among consumers?

Upvotes: 0

Views: 297

Answers (1)

jackko
jackko

Reputation: 7344

How can we configure the rest api url based on the environment (local/dev/qa/prod)?

Hard to answer without more detail. This is more about configuring any variable based on the environment; your API endpoint is just example.

The rest API url might change every-time we deploy the application to AWS (Link gets generated in AWS API Gateway), Have we have to manually update the url list in the react app? Do we have a way to sync these urls among consumers?

  1. You should implement the build/deploy process such that the API is not destroyed and recreated. Cloudwatch metrics and logs are tied to the API by its ID so your monitoring would also break. Of course, having a stable endpoint is important too.
  2. I recommend looking at custom domains as well. You could even integrate your environment into the custom domain URL in a structured way i.e. prod.myendpoint.company.com or myendpoint.company.com/prod.

Upvotes: 0

Related Questions