From cff8b272b1631661b8d5f5f4b59bd534ad8c86ca Mon Sep 17 00:00:00 2001 From: Pierre-Alain TORET Date: Tue, 17 Apr 2018 11:14:32 +0200 Subject: Support hostname binding in config * Add basic support for hostname binding Signed-off-by: Pierre-Alain TORET * Make production example a bit more secure Signed-off-by: Pierre-Alain TORET * Make example config files compatible with hostname binding modification Signed-off-by: Pierre-Alain TORET * Fix typo Signed-off-by: Pierre-Alain TORET * Bind on 127.0.0.1 by default Signed-off-by: Pierre-Alain TORET * Update Docker configuration with hostname binding Signed-off-by: Pierre-Alain TORET --- config/default.yaml | 1 + config/production.yaml.example | 1 + server.ts | 5 +++-- server/initializers/checker.ts | 2 +- server/initializers/constants.ts | 3 ++- support/docker/production/config/production.yaml | 1 + 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/config/default.yaml b/config/default.yaml index bf772faf6..9f4a76621 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -1,4 +1,5 @@ listen: + hostname: '127.0.0.1' port: 9000 webserver: diff --git a/config/production.yaml.example b/config/production.yaml.example index c963118d9..fc06c51fb 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example @@ -1,4 +1,5 @@ listen: + hostname: 'localhost' port: 9000 # Correspond to your reverse proxy "listen" configuration diff --git a/server.ts b/server.ts index 06d575c86..5323bae2b 100644 --- a/server.ts +++ b/server.ts @@ -194,6 +194,7 @@ app.use(function (err, req, res, next) { async function startApplication () { const port = CONFIG.LISTEN.PORT + const hostname = CONFIG.LISTEN.HOSTNAME await installApplication() @@ -214,7 +215,7 @@ async function startApplication () { Redis.Instance.init() // Make server listening - server.listen(port) - logger.info('Server listening on port %d', port) + server.listen(port, hostname) + logger.info('Server listening on %s:%d', hostname, port) logger.info('Web server: %s', CONFIG.WEBSERVER.URL) } diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index 45f1d79c3..71f303963 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts @@ -18,7 +18,7 @@ function checkConfig () { // Check the config files function checkMissedConfig () { - const required = [ 'listen.port', + const required = [ 'listen.port', 'listen.hostname', 'webserver.https', 'webserver.hostname', 'webserver.port', 'trust_proxy', 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 2622b2c71..56d39529e 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -86,7 +86,8 @@ let SCHEDULER_INTERVAL = 60000 * 60 const CONFIG = { CUSTOM_FILE: getLocalConfigFilePath(), LISTEN: { - PORT: config.get('listen.port') + PORT: config.get('listen.port'), + HOSTNAME: config.get('listen.hostname') }, DATABASE: { DBNAME: 'peertube' + config.get('database.suffix'), diff --git a/support/docker/production/config/production.yaml b/support/docker/production/config/production.yaml index 7b6de32e5..8a58c5b16 100644 --- a/support/docker/production/config/production.yaml +++ b/support/docker/production/config/production.yaml @@ -1,4 +1,5 @@ listen: + hostname: '127.0.0.1' port: 9000 # Correspond to your reverse proxy "listen" configuration -- cgit v1.2.3