mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	handle options per route
This commit is contained in:
		| @@ -172,6 +172,12 @@ 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) { |         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); |             corsHandler(req,res,next); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| @@ -266,9 +272,7 @@ module.exports = function(RED) { | |||||||
|             } else if (this.method == "head") { |             } else if (this.method == "head") { | ||||||
|                 RED.httpNode.head(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,this.callback,this.errorHandler); |                 RED.httpNode.head(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,this.callback,this.errorHandler); | ||||||
|             } else if (this.method == "options") { |             } else if (this.method == "options") { | ||||||
|                 RED.httpNode.options(this.url,cookieParser(),httpMiddleware,corsHandler,metricsHandler,function name(req,res,next) { |                 RED.httpNode.options(this.url,cookieParser(),httpMiddleware,metricsHandler,this.callback,this.errorHandler); | ||||||
|                     this.callback(req,res,next) |  | ||||||
|                 },this.errorHandler); |  | ||||||
|             } else if (this.method == "trace") { |             } else if (this.method == "trace") { | ||||||
|                 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); | ||||||
|             } else if (this.method == "connect") { |             } else if (this.method == "connect") { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user