Add httpNodeMiddleware option

Closes #631

Enables custom middleware to be inserted in front of all HTTP In
nodes.
This commit is contained in:
Nick O'Leary
2015-05-13 21:25:37 +01:00
parent 17f3366556
commit d28a6eaf9d
2 changed files with 21 additions and 4 deletions

View File

@@ -76,6 +76,14 @@ module.exports = function(RED) {
RED.httpNode.options(this.url,corsHandler);
}
var httpMiddleware = function(req,res,next) { next(); }
if (RED.settings.httpNodeMiddleware) {
if (typeof RED.settings.httpNodeMiddleware === "function") {
httpMiddleware = RED.settings.httpNodeMiddleware;
}
}
var metricsHandler = function(req,res,next) { next(); }
if (this.metric()) {
@@ -97,13 +105,13 @@ module.exports = function(RED) {
}
if (this.method == "get") {
RED.httpNode.get(this.url,corsHandler,metricsHandler,this.callback,this.errorHandler);
RED.httpNode.get(this.url,httpMiddleware,corsHandler,metricsHandler,this.callback,this.errorHandler);
} else if (this.method == "post") {
RED.httpNode.post(this.url,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
RED.httpNode.post(this.url,httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
} else if (this.method == "put") {
RED.httpNode.put(this.url,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
RED.httpNode.put(this.url,httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
} else if (this.method == "delete") {
RED.httpNode.delete(this.url,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
RED.httpNode.delete(this.url,httpMiddleware,corsHandler,metricsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
}
this.on("close",function() {