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

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

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 Denunciar

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 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