1
0
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:
Steve-Mcl 2022-03-10 08:01:17 +00:00
parent af899b9fc3
commit f49b40cc3a

View File

@ -171,17 +171,18 @@ module.exports = function(RED) {
if (RED.settings.httpNodeCors) { if (RED.settings.httpNodeCors) {
corsHandler = cors(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) { function HTTPIn(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
if (RED.settings.httpNodeRoot !== false) { 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); RED.httpNode.patch(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
} else if (this.method == "delete") { } else if (this.method == "delete") {
RED.httpNode.delete(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler); 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 } 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); RED.httpNode.trace(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
} }