From f49b40cc3a1d504c7d5e31f0a4e4f8faf5f75b41 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Thu, 10 Mar 2022 08:01:17 +0000 Subject: [PATCH] Fix sub-path OPTIONS routes not called --- .../@node-red/nodes/core/network/21-httpin.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httpin.js b/packages/node_modules/@node-red/nodes/core/network/21-httpin.js index 1034012ec..1986970a1 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httpin.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httpin.js @@ -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); }