mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
e48cbafbd6
commit
55c830b812
3
red.js
3
red.js
@ -99,11 +99,14 @@ if (settings.httpRoot === false) {
|
|||||||
settings.httpNodeRoot = false;
|
settings.httpNodeRoot = false;
|
||||||
} else {
|
} else {
|
||||||
settings.httpRoot = settings.httpRoot||"/";
|
settings.httpRoot = settings.httpRoot||"/";
|
||||||
|
settings.disableEditor = settings.disableEditor||false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.httpAdminRoot !== false) {
|
if (settings.httpAdminRoot !== false) {
|
||||||
settings.httpAdminRoot = formatRoot(settings.httpAdminRoot || settings.httpRoot || "/");
|
settings.httpAdminRoot = formatRoot(settings.httpAdminRoot || settings.httpRoot || "/");
|
||||||
settings.httpAdminAuth = settings.httpAdminAuth || settings.httpAuth;
|
settings.httpAdminAuth = settings.httpAdminAuth || settings.httpAuth;
|
||||||
|
} else {
|
||||||
|
settings.disableEditor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.httpNodeRoot !== false) {
|
if (settings.httpNodeRoot !== false) {
|
||||||
|
@ -36,6 +36,7 @@ function init(_server,_settings) {
|
|||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
|
|
||||||
|
if (!settings.disableEditor) {
|
||||||
var webSocketKeepAliveTime = settings.webSocketKeepAliveTime || 15000;
|
var webSocketKeepAliveTime = settings.webSocketKeepAliveTime || 15000;
|
||||||
var path = settings.httpAdminRoot || "/";
|
var path = settings.httpAdminRoot || "/";
|
||||||
path = path + (path.slice(-1) == "/" ? "":"/") + "comms";
|
path = path + (path.slice(-1) == "/" ? "":"/") + "comms";
|
||||||
@ -81,11 +82,16 @@ function start() {
|
|||||||
}
|
}
|
||||||
}, webSocketKeepAliveTime);
|
}, webSocketKeepAliveTime);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function stop() {
|
function stop() {
|
||||||
|
if (heartbeatTimer) {
|
||||||
clearInterval(heartbeatTimer);
|
clearInterval(heartbeatTimer);
|
||||||
|
}
|
||||||
|
if (wsServer) {
|
||||||
wsServer.close();
|
wsServer.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function publish(topic,data,retain) {
|
function publish(topic,data,retain) {
|
||||||
if (retain) {
|
if (retain) {
|
||||||
|
@ -22,20 +22,28 @@ var exec = require('child_process').exec;
|
|||||||
var createUI = require("./ui");
|
var createUI = require("./ui");
|
||||||
var redNodes = require("./nodes");
|
var redNodes = require("./nodes");
|
||||||
var comms = require("./comms");
|
var comms = require("./comms");
|
||||||
|
var storage = require("./storage");
|
||||||
|
|
||||||
var app = null;
|
var app = null;
|
||||||
var nodeApp = null;
|
var nodeApp = null;
|
||||||
var server = null;
|
var server = null;
|
||||||
var settings = null;
|
var settings = null;
|
||||||
var storage = null;
|
|
||||||
|
|
||||||
function createServer(_server,_settings) {
|
function createServer(_server,_settings) {
|
||||||
server = _server;
|
server = _server;
|
||||||
settings = _settings;
|
settings = _settings;
|
||||||
|
|
||||||
comms.init(_server,_settings);
|
comms.init(_server,_settings);
|
||||||
storage = require("./storage");
|
|
||||||
app = createUI(settings);
|
|
||||||
nodeApp = express();
|
nodeApp = express();
|
||||||
|
app = express();
|
||||||
|
|
||||||
|
if (settings.httpAdminRoot !== false) {
|
||||||
|
|
||||||
|
|
||||||
|
if (!settings.disableEditor) {
|
||||||
|
createUI(settings,app);
|
||||||
|
}
|
||||||
|
|
||||||
app.get("/flows",function(req,res) {
|
app.get("/flows",function(req,res) {
|
||||||
res.json(redNodes.getFlows());
|
res.json(redNodes.getFlows());
|
||||||
@ -57,7 +65,6 @@ function createServer(_server,_settings) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
app.get("/nodes",function(req,res) {
|
app.get("/nodes",function(req,res) {
|
||||||
if (req.get("accept") == "application/json") {
|
if (req.get("accept") == "application/json") {
|
||||||
res.json(redNodes.getNodeList());
|
res.json(redNodes.getNodeList());
|
||||||
@ -200,7 +207,7 @@ function createServer(_server,_settings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function reportAddedModules(info) {
|
function reportAddedModules(info) {
|
||||||
comms.publish("node/added",info,false);
|
comms.publish("node/added",info,false);
|
||||||
@ -330,7 +337,6 @@ function start() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
defer.resolve();
|
defer.resolve();
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013 IBM Corp.
|
* Copyright 2013, 2014 IBM Corp.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -15,7 +15,6 @@
|
|||||||
**/
|
**/
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var app = express();
|
|
||||||
var events = require("./events");
|
var events = require("./events");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
@ -28,9 +27,9 @@ events.on("node-icon-dir",function(dir) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function setupUI(_settings) {
|
function setupUI(_settings,app) {
|
||||||
|
|
||||||
settings = _settings; // TODO confirm if settings are needed
|
settings = _settings;
|
||||||
|
|
||||||
// Need to ensure the url ends with a '/' so the static serving works
|
// Need to ensure the url ends with a '/' so the static serving works
|
||||||
// with relative paths
|
// with relative paths
|
||||||
|
@ -55,6 +55,7 @@ module.exports = {
|
|||||||
|
|
||||||
// By default, the Node-RED UI is available at http://localhost:1880/
|
// By default, the Node-RED UI is available at http://localhost:1880/
|
||||||
// The following property can be used to specifiy a different root path.
|
// The following property can be used to specifiy a different root path.
|
||||||
|
// If set to false, this is disabled.
|
||||||
//httpAdminRoot: '/admin',
|
//httpAdminRoot: '/admin',
|
||||||
|
|
||||||
// You can protect the user interface with a userid and password by using the following property.
|
// You can protect the user interface with a userid and password by using the following property.
|
||||||
@ -63,7 +64,8 @@ module.exports = {
|
|||||||
|
|
||||||
// Some nodes, such as HTTP In, can be used to listen for incoming http requests.
|
// Some nodes, such as HTTP In, can be used to listen for incoming http requests.
|
||||||
// By default, these are served relative to '/'. The following property
|
// By default, these are served relative to '/'. The following property
|
||||||
// can be used to specifiy a different root path.
|
// can be used to specifiy a different root path. If set to false, this is
|
||||||
|
// disabled.
|
||||||
//httpNodeRoot: '/nodes',
|
//httpNodeRoot: '/nodes',
|
||||||
|
|
||||||
// To password protect the node-defined HTTP endpoints, the following property
|
// To password protect the node-defined HTTP endpoints, the following property
|
||||||
@ -88,6 +90,11 @@ module.exports = {
|
|||||||
// to apply the same authentication to both parts.
|
// to apply the same authentication to both parts.
|
||||||
//httpAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"},
|
//httpAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"},
|
||||||
|
|
||||||
|
// The following property can be used to disable the editor. The admin API
|
||||||
|
// is not affected by this option. To disable both the editor and the admin
|
||||||
|
// API, use either the httpRoot or httpAdminRoot properties
|
||||||
|
//disableEditor: false,
|
||||||
|
|
||||||
// The following property can be used to enable HTTPS
|
// The following property can be used to enable HTTPS
|
||||||
// See http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
|
// See http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
|
||||||
// for details on its contents.
|
// for details on its contents.
|
||||||
|
@ -15,10 +15,13 @@
|
|||||||
**/
|
**/
|
||||||
var request = require("supertest");
|
var request = require("supertest");
|
||||||
var express = require("express");
|
var express = require("express");
|
||||||
|
var redUI = require("../../red/ui");
|
||||||
|
|
||||||
|
|
||||||
describe("red/ui icon handler", function() {
|
describe("red/ui icon handler", function() {
|
||||||
it('returns the default icon when getting an unknown icon', function(done) {
|
it('returns the default icon when getting an unknown icon', function(done) {
|
||||||
var app = require("../../red/ui")();
|
var app = express();
|
||||||
|
redUI({},app);
|
||||||
request(app)
|
request(app)
|
||||||
.get("/icons/youwonthaveme.png")
|
.get("/icons/youwonthaveme.png")
|
||||||
.expect('Content-Type', /image\/png/)
|
.expect('Content-Type', /image\/png/)
|
||||||
@ -32,7 +35,8 @@ describe("red/ui icon handler", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns an icon from disk', function(done) {
|
it('returns an icon from disk', function(done) {
|
||||||
var app = require("../../red/ui")();
|
var app = express();
|
||||||
|
redUI({},app);
|
||||||
request(app)
|
request(app)
|
||||||
.get("/icons/arduino.png")
|
.get("/icons/arduino.png")
|
||||||
.expect('Content-Type', /image\/png/)
|
.expect('Content-Type', /image\/png/)
|
||||||
@ -82,7 +86,8 @@ describe("icon cache handler", function() {
|
|||||||
* the default PNG would be served
|
* the default PNG would be served
|
||||||
*/
|
*/
|
||||||
it('returns an icon using icon cache', function(done) {
|
it('returns an icon using icon cache', function(done) {
|
||||||
var app = require("../../red/ui")();
|
var app = express();
|
||||||
|
redUI({},app);
|
||||||
events.emit("node-icon-dir", tempDir);
|
events.emit("node-icon-dir", tempDir);
|
||||||
request(app)
|
request(app)
|
||||||
.get("/icons/cacheMe.png")
|
.get("/icons/cacheMe.png")
|
||||||
@ -117,8 +122,8 @@ describe("red/ui settings handler", function() {
|
|||||||
httpNodeRoot: "testHttpNodeRoot",
|
httpNodeRoot: "testHttpNodeRoot",
|
||||||
version: "testVersion",
|
version: "testVersion",
|
||||||
};
|
};
|
||||||
var app = require("../../red/ui")(settings);
|
var app = express();
|
||||||
|
redUI(settings,app);
|
||||||
request(app)
|
request(app)
|
||||||
.get("/settings")
|
.get("/settings")
|
||||||
.expect('Content-Type', /application\/json/)
|
.expect('Content-Type', /application\/json/)
|
||||||
@ -135,7 +140,8 @@ describe("red/ui settings handler", function() {
|
|||||||
|
|
||||||
describe("red/ui root handler", function() {
|
describe("red/ui root handler", function() {
|
||||||
it('server up the main page', function(done) {
|
it('server up the main page', function(done) {
|
||||||
var app = require("../../red/ui")();
|
var app = express();
|
||||||
|
redUI({},app);
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.get("/")
|
.get("/")
|
||||||
@ -151,7 +157,10 @@ describe("red/ui root handler", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('redirects to path ending with /', function(done) {
|
it('redirects to path ending with /', function(done) {
|
||||||
var app = express().use('/root', require("../../red/ui")());
|
var rapp = express();
|
||||||
|
redUI({},rapp);
|
||||||
|
|
||||||
|
var app = express().use('/root', rapp);
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.get("/root")
|
.get("/root")
|
||||||
|
Loading…
Reference in New Issue
Block a user