Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.3K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda