Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify HOST for express server to listen on #190

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ if (app.get('env') === 'development') {

// App configuration for all environments
app.set('port', process.env.PORT || 3000);
app.set('host', process.env.HOST || '0.0.0.0');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about something like this, and remove the line setting this on the app?

  var server_params = {
            port :  process.env.PORT || 3000
        }
        
        if(process.env.HOST){
            server_params.host = process.env.HOST;
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any pros and cons to this change unless the configuration is needed elsewhere in the application. In addition, the possibility of setting a default value is lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, you can not view the configuration in the log

app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(favicon(__dirname + '/public/img/favicon.ico'));
Expand Down Expand Up @@ -338,9 +339,16 @@ app.use(function (req, res, next) {

app.use(serveStatic(path.join(__dirname, 'public')));

var server = app.listen(system.getNodeProcessPort(), function () {
logger.info('openHAB-cloud: express server listening on port ' + system.getNodeProcessPort());
var server_params = {'port': system.getNodeProcessPort()};

if (app.get('host') != '0.0.0.0') {
server_params.host = app.get('host')
}

var server = app.listen(server_params, function () {
logger.info('openHAB-cloud: express server listening on ' + app.get('host') + ':' + system.getNodeProcessPort());
});


var io = require('socket.io').listen(server, {
logger: logger
Expand Down