Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

368
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!