"Access-Control-Allow-Origin" is not added to headers
See original GitHub issueIt started with having problem for CORS between my front-end (angular2) and back-end (expressjs). Some StackOverflow recommend to use cors-package (for answers in 2016 against those from 2013-2014).
I’ve used following configuration and CORS still not adding “Access-Control-Allow-Origin”:
cors = require('cors'),
const originsWhiteList = {
"http://localhost:3001": true // front-end development port
};
const corsOptions = {
origin: function(origin, callback) {
callback(originsWhiteList[origin] ? null : 'Bad Request', originsWhiteList[origin]);
},
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE']
}
.
.
.
// just right before other routes
app.use(cors(corsOptions));
app.options('/api/v1/*', cors());
this should be classified as bug, right ?
the exact error:
XMLHttpRequest cannot load http://localhost:3000/api/v1/todos. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:3001’ is therefore not allowed access. The response had HTTP status code 403.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Reason: CORS header 'Access-Control-Allow-Origin' missing
The response to the CORS request is missing the required Access-Control-Allow-Origin header, which is used to determine whether or not the ...
Read more >Access-Control-Allow-Origin header not working
It seems that proper handling of the pre-flight OPTIONS request is necessary, but NOT SUFFICIENT for cross-site resource requests to work. After ...
Read more >Fixing "No 'Access-Control-Allow-Origin' Header Present"
This error occurs when a script on your website/web app attempts to make a request to a resource that isn't configured to accept...
Read more >3 Ways to Fix the CORS Error — and How the Access-Control ...
Fix one: install the Allow-Control-Allow-Origin plugin. The quickest fix you can make is to install the moesif CORS extension .
Read more >Resolve the "No 'Access-Control-Allow-Origin' header" error ...
Confirm the origin's cross-origin resource sharing (CORS) policy allows the origin to return the Access-Control-Allow-Origin header · Configure the CloudFront ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
the readme file state the second callback’s parameter is a boolean
So after spending the past week getting to know this module better to help maintain it–it turns out that both are correct. The second argument you give to the callback can actually be any valid value to the
origin
option (so, an array, a string, a boolean, etc.).