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

263
Views
Access-Control-Allow-Origin axios request error - CORS

I have a problem with CORS while sending POST request:

Here is my code:

import axios from 'axios'

const api = axios.create({
  baseURL: 'http://localhost:8084',
})


export const postTip = async (payload) => {
  try {
    const { data } = await api.post(`post-tip`, payload);
    return data;
  } catch (e) {
    return [];
  }
};

I have found that I need to set Access-Control-Allow-Origin in headers, and I did it in 2 ways. First one:

const api = axios.create({
  baseURL: 'http://localhost:8084',
  headers: {
    post: {
      "Access-Control-Allow-Origin": true
    }
  }
})

And the second one:

const { data } = await api.post(`post-tip`, payload, {
      headers: {
        "Access-Control-Allow-Origin": true
      }
    });

Both of them work and in request header I can see this line Access-Control-Allow-Origin: true. But I still get this error, so, what's the problem?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This error from your backend, you use axios post from front-end, but you need to set header "Access-Control-Allow-Origin": true on your backend.

about 4 years ago · Juan Pablo Isaza Report

0

this error is probably coming from the server. Are you trying to reach your own api? If you do the error might be there.

I see you tagged express so please refer to this page it should contain all the information you need

http://expressjs.com/en/resources/middleware/cors.html

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!