From 15002f68725145e21cc7767eca4110bd0bf0a951 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 8 Mar 2014 22:35:35 +0000 Subject: [PATCH] Add headless mode closes #2 httpAdminRoot / httpNodeRoot can be set to false to disable their respective bits. If both are set to false, (or httpRoot is set to false), and httpStatic is not defined, then it will not start the http server. --- nodes/core/io/21-httpin.js | 93 ++++++++++++++++++++------------------ red.js | 61 ++++++++++++++++++------- 2 files changed, 94 insertions(+), 60 deletions(-) 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