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

565
Visualizações
Error CORS when i want redirecting localhost:4000 to localhost:3000

i have a project with react and nodejs. now, i authenticate user in localhost:4000 (my server) then redirect to localhost:3000/*

const loginHandler = async (req, res,next) => {

passport.authenticate("local",{
  successRedirect:'http://localhost:3000/dashboard',
  failureRedirect:'http://localhost:3000/login',
  failureFlash: true
})(req,res,next)
};

but retrun this error

Access to XMLHttpRequest at 'http://localhost:3000/login' (redirected from 'http://localhost:4000/login') from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. loginForm.jsx:26 Error: Network Error

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, ports are treated as different origins. When the request is tried it asks if it is ok to do so by requeting the Cross-Origin Resource Sharing policy. And as the error suggests, the server at :3000 did not provide an Access-Control-Allow-Origin header. This header should list the domains allowing to contact it, or use wildcard.

If you are using express, see the CORS middleware to make this easy: https://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