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

266
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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