Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
How to configure fetch base url on deployment in docker for react app?

I have a React app with fetches from an API in it. I have a dockerfile that works.

How do I configure the base url for all fetches in production?

In the end I will deploy my React app on Azure App Services. I used the tag proxy in package.json, but this is only for development. An Example fetch looks like this: (before "/evaluations" the base url has to be placed)

    fetch(`/evaluations?onlyactiveones=true`, this.credentials)
        .then(response => response.text())
        .then(data => {
            this.setState({ evaluations: data });
            console.log(data);
        });
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Looks like you are making fetch calls to relative url. So by default it will make call to your domain as base url. For example in this case, http://yourdomain.com/evluations, but most likely you want to make call to http://someotherdomain.com/api/evaluations. In order to do that you need to configure reverse proxy in your azure web site (or any other hosting server)

In azure website you can configure reverse proxy as suggested in the following link: https://ppolyzos.com/2015/10/26/reverse-proxy-functionality-in-azure-web-sites/

over 4 years ago · Santiago Trujillo Report

0

I have now solved this problem. The things that I have done:

  1. Define a env variable for the base url, like: process.env.REACT_APP_API_PROXY
  2. Replace all fetches with this env variable. For the example above:

        fetch(`${process.env.REACT_APP_API_PROXY}/evaluations?onlyactiveones=true`, this.credentials)
        .then(response => response.text())
        .then(data => {
            this.setState({ evaluations: data });
            console.log(data);
        });
    
  3. Define the env variable as you like. The env variable has to be placed before building the react app, it can not be replaced at runtime.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!