Access to XMLHttpRequest at 'http://localhost:3001' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://localhost:3001/' that is not equal to the supplied origin.
const corsOptions = { origin: 'http://localhost:3001/', optionsSuccessStatus: 200, credentials: true } app.use(cors(corsOptions)); app.use((req,res,next)=>{ res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization'); next(); }) const PORT = process.env.PORT // 3001
Quote: origin: 'http://localhost:3001/'
origin: 'http://localhost:3001/'
http://localhost:3001/
Quote: ... from origin 'http://localhost:3000' ...
http://localhost:3000
3000
3001
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)