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 30dca83519
commit 1364dfc74d

View File

@ -171,6 +171,8 @@ 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);
@ -180,7 +182,6 @@ module.exports = function(RED) {
}
corsHandler(req,res,next);
});
}
function HTTPIn(n) {
RED.nodes.createNode(this,n);
@ -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);
}