diff --git a/nodes/core/io/21-httpin.js b/nodes/core/io/21-httpin.js index 1c213003f..5cf4d8979 100644 --- a/nodes/core/io/21-httpin.js +++ b/nodes/core/io/21-httpin.js @@ -43,61 +43,66 @@ function rawBodyParser(req, res, next) { function HTTPIn(n) { RED.nodes.createNode(this,n); - this.url = n.url; - this.method = n.method; + if (RED.settings.httpNodeRoot !== false) { - var node = this; - - this.errorHandler = function(err,req,res,next) { - node.warn(err); - res.send(500); - }; - - this.callback = function(req,res) { - if (node.method == "post") { - node.send({req:req,res:res,payload:req.body}); - } else if (node.method == "get") { - node.send({req:req,res:res,payload:req.query}); - } else { - node.send({req:req,res:res}); - } - } - - var corsHandler = function(req,res,next) { next(); } - - if (RED.settings.httpNodeCors) { - corsHandler = cors(RED.settings.httpNodeCors); - RED.httpNode.options(this.url,corsHandler); - } - - if (this.method == "get") { - RED.httpNode.get(this.url,corsHandler,this.callback,this.errorHandler); - } else if (this.method == "post") { - RED.httpNode.post(this.url,corsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler); - } else if (this.method == "put") { - RED.httpNode.put(this.url,corsHandler,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler); - } else if (this.method == "delete") { - RED.httpNode.delete(this.url,corsHandler,this.callback,errorHandler); - } + this.url = n.url; + this.method = n.method; - this.on("close",function() { - var routes = RED.httpNode.routes[this.method]; - for (var i = 0; i