I have my express server running on http://localhost:3000 (I call this web-server) I have another application running on localhost:8100 (I call this simply 'app')
When my app makes a call to the webserver I receive the message:
"XMLHTTPReqeust cannot load http://localhost:3000/auth/facebook. Response to preflight request doesn't pass access control check. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' when the credentials flag is true. Origin 'http://localhost:81000' is therefore not allowed acecss"
This message shows up in the browser console.
I have setup the following options in the middleware of my node webserver
res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT, POST,DELETE');
After reading few stackoverfow questions, I also added the following:
res.header('Access-Control-Allow-Origin', 'http://localhost:8100');
however this does not resolve the issue.
Enable All CORS Requests If you want to enable CORS for all the request you can simply use the cors middleware before configuring your routes: const express = require('express'); const cors = require('cors'); const app = express(); app.
1 Answer. Show activity on this post. Install cors library npm install cors --save and use it like so. I already bye-pass cors with request library.
CORS stands for Cross-Origin Resource Sharing . It allows us to relax the security applied to an API. This is done by bypassing the Access-Control-Allow-Origin headers, which specify which origins can access the API.
I use cors and implement it so, it's very simple
var cors=require('cors');
app.use(cors({origin:true,credentials: true}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With