1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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() {

View File

@ -125,6 +125,15 @@ module.exports = {
// http request node.
//httpNodeProxy : { host:"myproxy.acme.com", port:8080 },
// The following property can be used to add a custom middleware function
// in front of all http in nodes. This allows custom authentication to be
// applied to all http in nodes, or any other sort of common request processing.
//httpNodeMiddleware: function(req,res,next) {
// // Handle/reject the request, or pass it on to the http in node
// // by calling next();
// next();
//},
// Anything in this hash is globally available to all functions.
// It is accessed as context.global.
// eg: