add support for binding to specific interfaces

This allows someone to add host and port entries to the glass_config
file to change the default port, or bind to a specific interface.

For example:

 "host": "127.0.0.1",
 "port": "3000",

If you only want to bind on the local interface.
This commit is contained in:
Robert Drake 2018-03-07 15:23:17 -05:00
parent 5c3d57a1a1
commit a7ace2e73a
2 changed files with 5 additions and 3 deletions

3
app.js
View File

@ -76,6 +76,7 @@ app.use(function (err, req, res, next) {
}); });
module.exports = app; module.exports = app;
module.exports.glass_config = glass_config;
/** /**
* Global Variables * Global Variables
@ -740,4 +741,4 @@ function email_alert(alert_title, alert_message) {
} }
} }
console.log("[Glass Server] Bootup complete"); console.log("[Glass Server] Bootup complete");

View File

@ -12,7 +12,8 @@ var http = require('http');
* Get port from environment and store in Express. * Get port from environment and store in Express.
*/ */
var port = normalizePort(process.env.PORT || '3000'); var port = normalizePort(process.env.PORT || app.glass_config.port || '3000');
var interface = app.glass_config.host || '0.0.0.0';
app.set('port', port); app.set('port', port);
/** /**
@ -25,7 +26,7 @@ var server = http.createServer(app);
* Listen on provided port, on all network interfaces. * Listen on provided port, on all network interfaces.
*/ */
server.listen(port); server.listen(port, interface);
server.on('error', onError); server.on('error', onError);
server.on('listening', onListening); server.on('listening', onListening);