From c30870029e10c0bc3cf74963ac13adeb4c5255c2 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Tue, 8 Mar 2022 23:36:33 +0000 Subject: [PATCH] handle options per route --- .../@node-red/nodes/core/network/21-httpin.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 50bcf6eed..94e5c8e1c 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 @@ -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") {