mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix sub-path OPTIONS routes not called
This commit is contained in:
parent
30dca83519
commit
1364dfc74d
@ -171,17 +171,18 @@ 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);
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
function HTTPIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
if (RED.settings.httpNodeRoot !== false) {
|
||||
@ -278,6 +279,8 @@ module.exports = function(RED) {
|
||||
RED.httpNode.patch(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "delete") {
|
||||
RED.httpNode.delete(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "options") { // https://httpwg.org/specs/rfc7231.html#rfc.section.4.3.7
|
||||
RED.httpNode.options(this.url,cookieParser(),httpMiddleware,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
|
||||
} else if (this.method == "trace") { // https://httpwg.org/specs/rfc7231.html#rfc.section.4.3.8
|
||||
RED.httpNode.trace(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user