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

179
Visualizações
Calling API in production and development in react js

if the Url is localhost/8085

Then all api call will be made to localhost:9764/API

if the url is http://10.1xx.xx.xx:8085/Amp Then all api call using 10.1xx.xx.xx:9764/api...

Is This possible in React js?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can get the host name (window.location.host) and do anything from that (https://stackoverflow.com/a/54691801/7174186)

about 4 years ago · Juan Pablo Isaza Relatório

0

it works for me.

const url=""
if(process.env.NODE_EnV==="development"){
   url =localhost:8085
}else if(process.env.NODE_EnV==="production"){
   url = "http://10.1xx.xx.xx:8085/Amp "
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Assuming that your app was created with create-react-app, you can create two different .env files - .env.development and .env.production and create inside them variables with the same names. Therefore, if you run your app locally, the app will use variable values from .env.development and in production from .env.production.

//.env.development
REACT_APP_API_URL=ABC
//.env.production
REACT_APP_API_URL=DEF
//Component.tsx
const URL = process.env.REACT_APP_API_URL
about 4 years ago · Juan Pablo Isaza 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