mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
handle options per route
This commit is contained in:
parent
3ccebac16b
commit
c30870029e
@ -172,6 +172,12 @@ module.exports = function(RED) {
|
||||
if (RED.settings.httpNodeCors) {
|
||||
corsHandler = cors(RED.settings.httpNodeCors);
|
||||
RED.httpNode.options("*", function(req,res,next) {
|
||||
//see if any routes for this path exist & call next() otherwise call corsHandler
|
||||
const routes = RED.httpNode._router.stack.filter(e => e.route && e.route.path == req.path && e.route.methods.options === true);
|
||||
if(routes.length > 0) {
|
||||
next();
|
||||
return
|
||||
}
|
||||
corsHandler(req,res,next);
|
||||
});
|
||||
}
|
||||
@ -266,9 +272,7 @@ module.exports = function(RED) {
|
||||
} else if (this.method == "head") {
|
||||
RED.httpNode.head(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "options") {
|
||||
RED.httpNode.options(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,function name(req,res,next) {
|
||||
this.callback(req,res,next)
|
||||
},this.errorHandler);
|
||||
RED.httpNode.options(this.url,cookieParser(),httpMiddleware,metricsHandler,this.callback,this.errorHandler);
|
||||
} else if (this.method == "trace") {
|
||||
RED.httpNode.trace(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
|
||||
} else if (this.method == "connect") {
|
||||
|
Loading…
Reference in New Issue
Block a user