Allow port zero for Express (#1363)

* Allow uiPort to be 0 (i.e. distinguish from undefined).  When Express runs up, catch the real port number to settings.serverPort, and use that in getListenPath if set, else use uiPort.
This commit is contained in:
btsimonh 2017-09-17 09:30:39 +01:00 committed by Nick O'Leary
parent a42e99c4aa
commit b81940351f
1 changed files with 17 additions and 2 deletions

19
red.js
View File

@ -167,7 +167,16 @@ if (settings.httpNodeRoot !== false) {
settings.httpNodeAuth = settings.httpNodeAuth || settings.httpAuth;
}
settings.uiPort = parsedArgs.port||settings.uiPort||1880;
// if we got a port from command line, use it (even if 0)
// replicate (settings.uiPort = parsedArgs.port||settings.uiPort||1880;) but allow zero
if (parsedArgs.port !== undefined){
settings.uiPort = parsedArgs.port;
} else {
if (settings.uiPort === undefined){
settings.uiPort = 1880;
}
}
settings.uiHost = settings.uiHost||"0.0.0.0";
if (flowFile) {
@ -261,9 +270,14 @@ if (settings.httpStatic) {
}
function getListenPath() {
var port = settings.serverPort;
if (port === undefined){
port = settings.uiPort;
}
var listenPath = 'http'+(settings.https?'s':'')+'://'+
(settings.uiHost == '0.0.0.0'?'127.0.0.1':settings.uiHost)+
':'+settings.uiPort;
':'+port;
if (settings.httpAdminRoot !== false) {
listenPath += settings.httpAdminRoot;
} else if (settings.httpStatic) {
@ -292,6 +306,7 @@ RED.start().then(function() {
if (settings.httpAdminRoot === false) {
RED.log.info(RED.log._("server.admin-ui-disabled"));
}
settings.serverPort = server.address().port;
process.title = parsedArgs.title || 'node-red';
RED.log.info(RED.log._("server.now-running", {listenpath:getListenPath()}));
});