mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Separate out httpAdmin and httpNode
This commit is contained in:
@@ -83,7 +83,7 @@ InjectNode.prototype.close = function() {
|
||||
}
|
||||
}
|
||||
|
||||
RED.app.post("/inject/:id", function(req,res) {
|
||||
RED.httpAdmin.post("/inject/:id", function(req,res) {
|
||||
var node = RED.nodes.getNode(req.params.id);
|
||||
if (node != null) {
|
||||
try {
|
||||
|
@@ -80,7 +80,7 @@ DebugNode.send = function(msg) {
|
||||
|
||||
DebugNode.activeConnections = [];
|
||||
|
||||
var path = RED.settings.httpRoot || "/";
|
||||
var path = RED.settings.httpAdminRoot || "/";
|
||||
path = path + (path.slice(-1) == "/" ? "":"/") + "debug/ws";
|
||||
|
||||
DebugNode.wsServer = new ws.Server({server:RED.server,path:path});
|
||||
@@ -104,7 +104,7 @@ DebugNode.logHandler.on("log",function(msg) {
|
||||
});
|
||||
RED.nodes.addLogHandler(DebugNode.logHandler);
|
||||
|
||||
RED.app.post("/debug/:id/:state", function(req,res) {
|
||||
RED.httpAdmin.post("/debug/:id/:state", function(req,res) {
|
||||
var node = RED.nodes.getNode(req.params.id);
|
||||
var state = req.params.state;
|
||||
if (node != null) {
|
||||
|
@@ -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;
|
||||
|
@@ -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 {
|
||||
|
@@ -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);
|
||||
|
@@ -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 {
|
||||
|
@@ -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
|
||||
|
@@ -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));
|
||||
|
@@ -263,7 +263,7 @@ var oa = new OAuth(
|
||||
|
||||
var credentials = {};
|
||||
|
||||
RED.app.get('/twitter/:id', function(req,res) {
|
||||
RED.httpAdmin.get('/twitter/:id', function(req,res) {
|
||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||
if (credentials) {
|
||||
res.send(JSON.stringify({sn:credentials.screen_name}));
|
||||
@@ -272,12 +272,12 @@ RED.app.get('/twitter/:id', function(req,res) {
|
||||
}
|
||||
});
|
||||
|
||||
RED.app.delete('/twitter/:id', function(req,res) {
|
||||
RED.httpAdmin.delete('/twitter/:id', function(req,res) {
|
||||
RED.nodes.deleteCredentials(req.params.id);
|
||||
res.send(200);
|
||||
});
|
||||
|
||||
RED.app.get('/twitter/:id/auth', function(req, res){
|
||||
RED.httpAdmin.get('/twitter/:id/auth', function(req, res){
|
||||
var credentials = {};
|
||||
oa.getOAuthRequestToken({
|
||||
oauth_callback: req.query.callback
|
||||
@@ -297,7 +297,7 @@ RED.app.get('/twitter/:id/auth', function(req, res){
|
||||
});
|
||||
});
|
||||
|
||||
RED.app.get('/twitter/:id/auth/callback', function(req, res, next){
|
||||
RED.httpAdmin.get('/twitter/:id/auth/callback', function(req, res, next){
|
||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||
credentials.oauth_verifier = req.query.oauth_verifier;
|
||||
|
||||
|
Reference in New Issue
Block a user