-
-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add debug to cors middleware #234
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I added a few comments and I also tagged it in that documentation should be added to the README so users will know how to enable the debugging and what the different messages mean and how to use it to diagnose their cors issues. You can always wait on the docs until the code is settled as well if you like.
@@ -4,6 +4,7 @@ | |||
|
|||
var assign = require('object-assign'); | |||
var vary = require('vary'); | |||
var debug = require('debug')('express:cors'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this should just be the name of the npm module: cors
.
@@ -13,6 +13,7 @@ | |||
"repository": "expressjs/cors", | |||
"main": "./lib/index.js", | |||
"dependencies": { | |||
"debug": "^4.3.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would set this to the same version express uses, or at least one compatible with the version range of this module.
@@ -17,50 +18,61 @@ | |||
} | |||
|
|||
function isOriginAllowed(origin, allowedOrigin) { | |||
debug('test of origin %s. AllowedOrigin: %O', origin, allowedOrigin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can likely simply this entire block by creating a new variable to store the true
/false
and then have a single debug
call at the end with what was checked and the result. This would also fix the issue here where given an array, it will never log isAllowedOrigin false
.
var requestOrigin = req.headers.origin, | ||
headers = [], | ||
isAllowed; | ||
|
||
if (!options.origin || options.origin === '*') { | ||
// allow any origin | ||
debug('added header Access-Control-Allow-Origin *'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than duplicating this on every single header add line, you could just place a single call when the headers are populated to list them.
Closes #233
This is a PR to add a debug to middleware cors.