-
Notifications
You must be signed in to change notification settings - Fork 277
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
Added CORS support for both HTTP and HTTPS servers. #111
Conversation
while creating http server/ https server, opts / sslOpts are already sent as parameters. add opts['cors'] object to the opts / sslOpts. opts['cors'] needs the key opts['cors']['allow'] = true If opts['cors']['allow'] is not sent in specified format, it will just ignore it and work as if no CORS is added. For now, all requests originating from any source would be allowed. Ability to filter the requests can be added in future.
lib/proxy.js
Outdated
function allowCORS(objServer, opts){ | ||
if(_.isEmpty(opts['cors']) === false && opts['cors']['allow'] && opts['cors']['allow'] === true){ | ||
objServer.use(function(req, res, next) { | ||
res.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.
redbird is not implemented using express, so .use
is not available. This would need to be implemented directly on nodejs http object.
Sorry for the late response. Please check the comment. |
my bad... shall do it as required. |
while creating http server/ https server, opts / sslOpts are already sent as parameters. add opts['cors'] object to the opts / sslOpts. opts['cors'] needs the key opts['cors']['allow'] = true If opts['cors']['allow'] is not sent in specified format, it will just ignore it and work as if no CORS is added. For now, all requests originating from any source would be allowed. Ability to filter the requests can be added in future.
lib/proxy.js
Outdated
@@ -781,15 +785,14 @@ function setHttp(link) { | |||
|
|||
// To allow CORS | |||
|
|||
function allowCORS(objServer, opts){ | |||
function allowCORS(res, opts){ | |||
if(_.isEmpty(opts['cors']) === false && opts['cors']['allow'] && opts['cors']['allow'] === true){ |
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.
wouldn't be the same to just check if opts.cors
is defined? like:
if(opts.cors){
...
}
// To allow CORS | ||
|
||
function allowCORS(res, opts){ | ||
if(_.isEmpty(opts['cors']) === false && opts['cors']['allow'] && opts['cors']['allow'] === true){ |
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.
Simplfy this expression to just if(opts.cors)
@OSSDeveloper yo!. We are very close to merge this one. Would be nice if you could address the feedback :). |
Why not allow each domain to has it's own preferred CORS rules? |
closing due to lack of response |
Closed on an afk? sad. +1 for this. I'm starting up a project. I'm using redbird. ...and I will use cors, but it isn't a top priority just yet. If this PR isn't picked back up; I might just. :) Thanks for your work here @manast |
afk for 2 years is not enough to close a PR? |
bump |
well, we could always fork |
while creating
http server/ https server
, opts / sslOpts are already sent as parameters.add
opts['cors']
object to the opts / sslOpts.opts['cors']
needs the keyopts['cors']['allow'] = true
If
opts['cors']['allow']
is not sent in specified format, it will just ignore it and work as if no CORS is added.For now, all requests originating from any source would be allowed.
Ability to filter the requests can be added in future.