Separate out httpAdmin and httpNode

This commit is contained in:
Nick O'Leary
2014-02-16 00:39:30 +00:00
parent e6cf783d52
commit 7c24d4d760
15 changed files with 121 additions and 55 deletions

View File

@@ -33,7 +33,7 @@ RED.nodes.registerType("mqtt-broker",MQTTBrokerNode);
var querystring = require('querystring');
RED.app.get('/mqtt-broker/:id',function(req,res) {
RED.httpAdmin.get('/mqtt-broker/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
@@ -42,12 +42,12 @@ RED.app.get('/mqtt-broker/:id',function(req,res) {
}
});
RED.app.delete('/mqtt-broker/:id',function(req,res) {
RED.httpAdmin.delete('/mqtt-broker/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.app.post('/mqtt-broker/:id',function(req,res) {
RED.httpAdmin.post('/mqtt-broker/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;

View File

@@ -80,7 +80,7 @@
if (this.name) {
return this.name;
} else if (this.url) {
var root = document.location.pathname.slice(0,-1);
var root = RED.settings.httpNodeRoot.slice(0,-1);
root += this.url;
return "["+this.method+"] "+root;
} else {

View File

@@ -58,17 +58,17 @@ function HTTPIn(n) {
else node.send({req:req,res:res});
}
if (this.method == "get") {
RED.app.get(this.url,this.callback,this.errorHandler);
RED.httpNode.get(this.url,this.callback,this.errorHandler);
} else if (this.method == "post") {
RED.app.post(this.url,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
RED.httpNode.post(this.url,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
} else if (this.method == "put") {
RED.app.put(this.url,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
RED.httpNode.put(this.url,jsonParser,urlencParser,rawBodyParser,this.callback,this.errorHandler);
} else if (this.method == "delete") {
RED.app.delete(this.url,this.callback,errorHandler);
RED.httpNode.delete(this.url,this.callback,errorHandler);
}
this.on("close",function() {
var routes = RED.app.routes[this.method];
var routes = RED.httpNode.routes[this.method];
for (var i in routes) {
if (routes[i].path == this.url) {
routes.splice(i,1);

View File

@@ -135,12 +135,12 @@
inputs:0,
outputs:0,
label: function() {
var root = document.location.pathname.slice(0,-1);
var root = RED.settings.httpNodeRoot.slice(0,-1);
root += this.path;
return root;
},
oneditprepare: function() {
var root = document.location.pathname.slice(0,-1);
var root = RED.settings.httpNodeRoot.slice(0,-1);
if (root == "") {
$("#node-config-ws-tip").hide();
} else {

View File

@@ -32,7 +32,7 @@ function WebSocketListenerNode(n) {
node._inputNodes = []; // collection of nodes that want to receive events
var path = RED.settings.httpRoot || "/";
var path = RED.settings.httpNodeRoot || "/";
path = path + (path.slice(-1) == "/" ? "":"/") + (node.path.charAt(0) == "/" ? node.path.substring(1) : node.path);
// Workaround https://github.com/einaros/ws/pull/253

View File

@@ -185,7 +185,7 @@ var serialPool = function() {
}
}();
RED.app.get("/serialports",function(req,res) {
RED.httpAdmin.get("/serialports",function(req,res) {
serialp.list(function (err, ports) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(JSON.stringify(ports));