Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

370
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda