Add disableEditor option

Closes #409
This commit is contained in:
Nick O'Leary 2014-09-22 14:33:26 +01:00
parent e48cbafbd6
commit 55c830b812
6 changed files with 262 additions and 232 deletions

3
red.js
View File

@ -99,11 +99,14 @@ if (settings.httpRoot === false) {
settings.httpNodeRoot = false;
} else {
settings.httpRoot = settings.httpRoot||"/";
settings.disableEditor = settings.disableEditor||false;
}
if (settings.httpAdminRoot !== false) {
settings.httpAdminRoot = formatRoot(settings.httpAdminRoot || settings.httpRoot || "/");
settings.httpAdminAuth = settings.httpAdminAuth || settings.httpAuth;
} else {
settings.disableEditor = true;
}
if (settings.httpNodeRoot !== false) {

View File

@ -36,6 +36,7 @@ function init(_server,_settings) {
function start() {
if (!settings.disableEditor) {
var webSocketKeepAliveTime = settings.webSocketKeepAliveTime || 15000;
var path = settings.httpAdminRoot || "/";
path = path + (path.slice(-1) == "/" ? "":"/") + "comms";
@ -81,11 +82,16 @@ function start() {
}
}, webSocketKeepAliveTime);
}
}
function stop() {
if (heartbeatTimer) {
clearInterval(heartbeatTimer);
}
if (wsServer) {
wsServer.close();
}
}
function publish(topic,data,retain) {
if (retain) {

View File

@ -22,20 +22,28 @@ var exec = require('child_process').exec;
var createUI = require("./ui");
var redNodes = require("./nodes");
var comms = require("./comms");
var storage = require("./storage");
var app = null;
var nodeApp = null;
var server = null;
var settings = null;
var storage = null;
function createServer(_server,_settings) {
server = _server;
settings = _settings;
comms.init(_server,_settings);
storage = require("./storage");
app = createUI(settings);
nodeApp = express();
app = express();
if (settings.httpAdminRoot !== false) {
if (!settings.disableEditor) {
createUI(settings,app);
}
app.get("/flows",function(req,res) {
res.json(redNodes.getFlows());
@ -57,7 +65,6 @@ function createServer(_server,_settings) {
}
);
app.get("/nodes",function(req,res) {
if (req.get("accept") == "application/json") {
res.json(redNodes.getNodeList());
@ -200,7 +207,7 @@ function createServer(_server,_settings) {
}
}
);
}
}
function reportAddedModules(info) {
comms.publish("node/added",info,false);
@ -330,7 +337,6 @@ function start() {
});
}
}
}
defer.resolve();

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013 IBM Corp.
* Copyright 2013, 2014 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,7 +15,6 @@
**/
var express = require('express');
var fs = require("fs");
var app = express();
var events = require("./events");
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
// with relative paths

View File

@ -55,6 +55,7 @@ module.exports = {
// By default, the Node-RED UI is available at http://localhost:1880/
// The following property can be used to specifiy a different root path.
// If set to false, this is disabled.
//httpAdminRoot: '/admin',
// 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.
// 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',
// 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.
//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
// See http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
// for details on its contents.

View File

@ -15,10 +15,13 @@
**/
var request = require("supertest");
var express = require("express");
var redUI = require("../../red/ui");
describe("red/ui icon handler", function() {
it('returns the default icon when getting an unknown icon', function(done) {
var app = require("../../red/ui")();
var app = express();
redUI({},app);
request(app)
.get("/icons/youwonthaveme.png")
.expect('Content-Type', /image\/png/)
@ -32,7 +35,8 @@ describe("red/ui icon handler", function() {
});
it('returns an icon from disk', function(done) {
var app = require("../../red/ui")();
var app = express();
redUI({},app);
request(app)
.get("/icons/arduino.png")
.expect('Content-Type', /image\/png/)
@ -82,7 +86,8 @@ describe("icon cache handler", function() {
* the default PNG would be served
*/
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);
request(app)
.get("/icons/cacheMe.png")
@ -117,8 +122,8 @@ describe("red/ui settings handler", function() {
httpNodeRoot: "testHttpNodeRoot",
version: "testVersion",
};
var app = require("../../red/ui")(settings);
var app = express();
redUI(settings,app);
request(app)
.get("/settings")
.expect('Content-Type', /application\/json/)
@ -135,7 +140,8 @@ describe("red/ui settings handler", function() {
describe("red/ui root handler", function() {
it('server up the main page', function(done) {
var app = require("../../red/ui")();
var app = express();
redUI({},app);
request(app)
.get("/")
@ -151,7 +157,10 @@ describe("red/ui root handler", function() {
});
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)
.get("/root")