From d4e6dfbf60df1a70d6cdc26338181dd92db930dc Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Tue, 19 Nov 2019 10:26:48 -0300 Subject: [PATCH] Allow specifying host to bind via BIND env var --- README.md | 3 ++- src/index.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 03ec0fc..9a6d6c2 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,8 @@ variables. For example: - Change base URL: `PEERCALLS__BASE_URL=/test` - app will now be accessible at `localhost:3000/test` - Enable HTTPS: `PEERCALLS__SSL='{"cert": "/path/to/cert.pem", "key": "/path/to/cert.key"}'` - Disable HTTPS: `PEERCALLS__SSL=undefined` - - Listen on a different port: `PORT=3001` + - Listen on a different port: `PORT=3001` (default is `3000`) + - Bind to specific IP or hostname: `BIND=127.0.0.1` See [config/default.yaml][config] for sample configuration. diff --git a/src/index.ts b/src/index.ts index 52aeeba..50036a2 100755 --- a/src/index.ts +++ b/src/index.ts @@ -8,8 +8,11 @@ import app from './server/app' const debug = _debug('peercalls') -const port = process.env.PORT || 3000 -app.listen(port, () => debug('Listening on: %s', port)) +const port = parseInt(process.env.PORT || '') || 3000 +const hostname = process.env.BIND +const server = app.listen( + port, hostname, () => debug('Listening on %s', server.address())) + process.on('SIGINT', () => process.exit()) process.on('SIGTERM', () => process.exit())