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

377
Visualizações
Node js Heroku No 'Access-Control-Allow-Origin' header is present on the requested resource

I have the following headers setup in my node js api app:

  res.header("Access-Control-Allow-Origin", "*");
  res.header(
    "Access-Control-Allow-Headers",
    "Origin, X-Requested, Content-Type, Accept Authorization"
  );
  if (req.method === "OPTIONS") {
    res.header(
      "Access-Control-Allow-Methods",
      "POST, PUT, PATCH, GET, DELETE"
    );
    return res.status(200).json({});
  }
  next();
});

With this config I can send GET, POST request to my api hosted in heroku from Postman. But when I try from my frontend app built with vue. I get the following error.

enter image description here

And I'm using fetch to send the request to remote api:

async signup() {
  try {
    const formData = new FormData();
    formData.firstName = this.firstName;
    formData.lastName = this.lastName;
    formData.email = this.email;
    formData.password = this.password;
    formData.confirmPassword = this.password;
    formData.mobile = this.mobile;
    formData.gender = this.gender;
    formData.profileImg = this.profileImg;
    const response = await fetch(
      "https://api-url.com/auth/patient/signup",
      {
        body: formData,
        method: "POST",
      }
    );
    const data = await response.json();
    this.response = JSON.stringify(data);
  } catch (error) {
    console.log(error);
  }
}

Can anyone point the mistakes I've made here ?

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

0

I think you need to set the headers in the fetch call. I see that you have already added body and method.

headers: { 'Content-Type': 'application/json' }
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