Add settings.uiHost - to allow binding to a specific interface

Closes #58
This commit is contained in:
Nicholas O'Leary 2013-11-08 14:50:54 +00:00
parent cb6fbf29a8
commit a2e77471a9
2 changed files with 14 additions and 3 deletions

11
red.js
View File

@ -39,6 +39,7 @@ if (settings.httpRoot.slice(-1) != "/") {
settings.httpRoot = settings.httpRoot + "/";
}
settings.uiPort = settings.uiPort||1880;
settings.uiHost = settings.uiHost||"0.0.0.0";
if (settings.httpAuth) {
app.use(settings.httpRoot,
@ -55,13 +56,17 @@ app.use(settings.httpRoot,red);
RED.start();
server.listen(settings.uiPort,function() {
util.log('[red] Server now running at http'+(settings.https?'s':'')+'://127.0.0.1:'+settings.uiPort+settings.httpRoot);
var listenPath = 'http'+(settings.https?'s':'')+'://'+
(settings.uiHost == '0.0.0.0'?'127.0.0.1':settings.uiHost)+
':'+settings.uiPort+settings.httpRoot;
server.listen(settings.uiPort,settings.uiHost,function() {
util.log('[red] Server now running at '+listenPath);
});
process.on('uncaughtException',function(err) {
if (err.errno === "EADDRINUSE") {
util.log('[red] Unable to listen on http'+(settings.https?'s':'')+'://127.0.0.1:'+settings.uiPort+settings.httpRoot);
util.log('[red] Unable to listen on '+listenPath);
util.log('[red] Error: port in use');
} else {
util.log('[red] Uncaught Exception:');

View File

@ -15,6 +15,12 @@
**/
module.exports = {
uiPort: 1880,
// By default, the Node-RED UI accepts connections on all IPv4 interfaces.
// The following property can be used to listen on a specific interface. For
// example, the following would only allow connections from the local machine.
//uiHost: "127.0.0.1",
mqttReconnectTime: 15000,
serialReconnectTime: 15000,
debugMaxLength: 1000,