mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add headless mode
closes #2 httpAdminRoot / httpNodeRoot can be set to false to disable their respective bits. If both are set to false, (or httpRoot is set to false), and httpStatic is not defined, then it will not start the http server.
This commit is contained in:
parent
5e58cc9fc1
commit
15002f6872
@ -43,6 +43,8 @@ function rawBodyParser(req, res, next) {
|
|||||||
|
|
||||||
function HTTPIn(n) {
|
function HTTPIn(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
if (RED.settings.httpNodeRoot !== false) {
|
||||||
|
|
||||||
this.url = n.url;
|
this.url = n.url;
|
||||||
this.method = n.method;
|
this.method = n.method;
|
||||||
|
|
||||||
@ -98,6 +100,9 @@ function HTTPIn(n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.warn("Cannot create http-in node when httpNodeRoot set to false");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("http in",HTTPIn);
|
RED.nodes.registerType("http in",HTTPIn);
|
||||||
|
35
red.js
35
red.js
@ -92,13 +92,24 @@ function formatRoot(root) {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.httpRoot === false) {
|
||||||
|
settings.httpAdminRoot = false;
|
||||||
|
settings.httpNodeRoot = false;
|
||||||
|
} else {
|
||||||
settings.httpRoot = settings.httpRoot||"/";
|
settings.httpRoot = settings.httpRoot||"/";
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("1:"+settings.httpNodeRoot);
|
||||||
|
if (settings.httpNodeRoot !== false) {
|
||||||
settings.httpNodeRoot = formatRoot(settings.httpNodeRoot || settings.httpRoot || "/");
|
settings.httpNodeRoot = formatRoot(settings.httpNodeRoot || settings.httpRoot || "/");
|
||||||
|
console.log("2:"+settings.httpNodeRoot);
|
||||||
settings.httpNodeAuth = settings.httpNodeAuth || settings.httpAuth;
|
settings.httpNodeAuth = settings.httpNodeAuth || settings.httpAuth;
|
||||||
|
}
|
||||||
|
|
||||||
settings.uiPort = settings.uiPort||1880;
|
settings.uiPort = settings.uiPort||1880;
|
||||||
settings.uiHost = settings.uiHost||"0.0.0.0";
|
settings.uiHost = settings.uiHost||"0.0.0.0";
|
||||||
@ -107,22 +118,28 @@ settings.flowFile = flowFile || settings.flowFile;
|
|||||||
|
|
||||||
RED.init(server,settings);
|
RED.init(server,settings);
|
||||||
|
|
||||||
if (settings.httpAdminAuth) {
|
if (settings.httpAdminRoot !== false && settings.httpAdminAuth) {
|
||||||
app.use(settings.httpAdminRoot,
|
app.use(settings.httpAdminRoot,
|
||||||
express.basicAuth(function(user, pass) {
|
express.basicAuth(function(user, pass) {
|
||||||
return user === settings.httpAdminAuth.user && crypto.createHash('md5').update(pass,'utf8').digest('hex') === settings.httpAdminAuth.pass;
|
return user === settings.httpAdminAuth.user && crypto.createHash('md5').update(pass,'utf8').digest('hex') === settings.httpAdminAuth.pass;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (settings.httpNodeAuth) {
|
if (settings.httpNodeRoot !== false && settings.httpNodeAuth) {
|
||||||
app.use(settings.httpNodeRoot,
|
app.use(settings.httpNodeRoot,
|
||||||
express.basicAuth(function(user, pass) {
|
express.basicAuth(function(user, pass) {
|
||||||
return user === settings.httpNodeAuth.user && crypto.createHash('md5').update(pass,'utf8').digest('hex') === settings.httpNodeAuth.pass;
|
return user === settings.httpNodeAuth.user && crypto.createHash('md5').update(pass,'utf8').digest('hex') === settings.httpNodeAuth.pass;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (settings.httpAdminRoot !== false) {
|
||||||
|
console.log("Attaching admin root");
|
||||||
app.use(settings.httpAdminRoot,RED.httpAdmin);
|
app.use(settings.httpAdminRoot,RED.httpAdmin);
|
||||||
|
}
|
||||||
|
if (settings.httpNodeRoot !== false) {
|
||||||
|
console.log(settings.httpNodeRoot);
|
||||||
app.use(settings.httpNodeRoot,RED.httpNode);
|
app.use(settings.httpNodeRoot,RED.httpNode);
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.httpStatic) {
|
if (settings.httpStatic) {
|
||||||
settings.httpStaticAuth = settings.httpStaticAuth || settings.httpAuth;
|
settings.httpStaticAuth = settings.httpStaticAuth || settings.httpAuth;
|
||||||
@ -137,13 +154,25 @@ if (settings.httpStatic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RED.start().then(function() {
|
RED.start().then(function() {
|
||||||
|
if (settings.httpAdminRoot !== false || settings.httpNodeRoot !== false || settings.httpStatic) {
|
||||||
var listenPath = 'http'+(settings.https?'s':'')+'://'+
|
var listenPath = 'http'+(settings.https?'s':'')+'://'+
|
||||||
(settings.uiHost == '0.0.0.0'?'127.0.0.1':settings.uiHost)+
|
(settings.uiHost == '0.0.0.0'?'127.0.0.1':settings.uiHost)+
|
||||||
':'+settings.uiPort+settings.httpAdminRoot;
|
':'+settings.uiPort;
|
||||||
|
if (settings.httpAdminRoot !== false) {
|
||||||
|
listenPath += settings.httpAdminRoot;
|
||||||
|
} else if (settings.httpStatic) {
|
||||||
|
listenPath += "/";
|
||||||
|
}
|
||||||
|
|
||||||
server.listen(settings.uiPort,settings.uiHost,function() {
|
server.listen(settings.uiPort,settings.uiHost,function() {
|
||||||
|
if (settings.httpAdminRoot === false) {
|
||||||
|
util.log('[red] Admin UI disabled');
|
||||||
|
}
|
||||||
util.log('[red] Server now running at '+listenPath);
|
util.log('[red] Server now running at '+listenPath);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
util.log('[red] Running in headless mode');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user