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

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

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