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

383
Visualizações
How to connect a frontend application on a different port with a backend?

I put my frontend application in the public folder for a node.js application and am getting the form-data using the following request:

try {
  await axios.post("/api/v1/contact-form", {
    name,
    email,
    msg,
  }); 
}

My backend is in port 5000 and it's handling the request by:

app.use("/api/v1/contact-form", submitFormRouter);

It works perfect. I'm getting the data when I have my frontend application is in the node.js public folder.

My question is if my frontend is running on a different local port such as, if I use "Five server" to run the frontend application, how do I replace the following path for post:

Frontend:

try {
  await axios.post("/api/v1/contact-form", {
    name,
    email,
    msg,
  });
}

Backend:

app.use("/api/v1/contact-form", submitFormRouter)

I've also tried the code using React in which case the frontend is running in http://localhost:3000/ and node.js server running in 5000, the code still works and I'm getting the form data. But, how do I make it work for a frontend application sitting in a different port(without react)?

Additionally, I hope you're kind enough to answer the following question- What would be the path once I have the frontend let's say on Netlify whereas the backend is on Heroku?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

What would be the path once I have the frontend let's say on Netlify whereas the backend is on Heroku?

Let's assume your Back on Heroku has this url https://app.herokuapp.com/ and the Front on Netlify this one https://app.netlify.com/. All you have to do is to give your Front your Back's url, like so:

try {
  await axios.post("https://app.herokuapp.com/api/v1/contact-form", {
    name,
    email,
    msg,
  });
}

My question is if my frontend is running on a different local port such as, if I use "Five server" to run the frontend application, how do I...

At this point you have two choices, the simplest one is to use a complete url like above. Let's assume your Front is on port 3000 and the Back on 8080. All you have to do again is:

try {
  await axios.post("http://localhost:8080/api/v1/contact-form", {
    name,
    email,
    msg,
  });
}

The second one is to use a proxy, and this really depends on your projects' structure and need.

about 4 years ago · Santiago Gelvez 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