From 4f808f13eb6301b14cce517664b4d2d35ad8c8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Sun, 6 May 2018 10:23:53 +0200 Subject: [PATCH] feat(bind): Added option to bind to http address. Closes #318 --- bin/unleash.js | 10 ++++++++-- lib/options.js | 1 + lib/server-impl.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/unleash.js b/bin/unleash.js index ea6d9952ca..aa4ddef936 100755 --- a/bin/unleash.js +++ b/bin/unleash.js @@ -15,6 +15,12 @@ const argv = require('yargs') default: 4242, type: 'number', }) + .option('host', { + alias: 'l', + describe: 'The HTTP address the server will accept connections on.', + demand: false, + type: 'string', + }) .option('databaseUrl', { alias: 'd', describe: @@ -25,9 +31,9 @@ const argv = require('yargs') serverImpl .start(argv) - .then(conf => + .then(() => console.log( - `Unleash started on http://localhost:${conf.app.get('port')}` + `Unleash started on http://${argv.host || '127.0.0.1'}:${argv.port}` ) ) .catch(console.err); diff --git a/lib/options.js b/lib/options.js index 59411c41b9..7cb4250155 100644 --- a/lib/options.js +++ b/lib/options.js @@ -8,6 +8,7 @@ const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000; const DEFAULT_OPTIONS = { databaseUrl: process.env.DATABASE_URL, port: process.env.HTTP_PORT || process.env.PORT || 4242, + host: undefined, baseUriPath: process.env.BASE_URI_PATH || '', serverMetrics: true, enableLegacyRoutes: true, diff --git a/lib/server-impl.js b/lib/server-impl.js index 983d99661a..95e1f0a64c 100644 --- a/lib/server-impl.js +++ b/lib/server-impl.js @@ -26,7 +26,7 @@ function createApp(options) { ); const app = getApp(config); - const server = app.listen(app.get('port'), () => { + const server = app.listen(app.get('port'), options.host, () => { logger.info(`Unleash started on ${app.get('port')}`); });