From ccce6056dd2df5a3e54f4d50defad35bc477da73 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Fri, 26 Apr 2019 08:45:45 +0200 Subject: [PATCH] Fix: Add support for IPC connections. Read this for more details: https://nodejs.org/api/net.html#net_identifying_paths_for_ipc_connections --- docs/getting-started.md | 4 +++- lib/options.js | 5 +++++ lib/server-impl.js | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 9abd785a94..8cfb5ad177 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -45,7 +45,9 @@ Available unleash options include: - **databaseUrl** - the postgres database url to connect to. Should include username/password. - **databaseSchema** - the postgres database schema to use. Defaults to 'public'. -- **port** - which port the unleash-server should bind to. +- **port** - which port the unleash-server should bind to. If port is omitted or is 0, the operating system will assign an arbitrary unused port. Will be ignored if pipe is specified. +- **host** - which host the unleash-server should bind to. If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. +- **pipe** - parameter to identify IPC endpoints. See https://nodejs.org/api/net.html#net_identifying_paths_for_ipc_connections for more details - **enableLegacyRoutes** (boolean) - allows you to turn on/off support for legacy routes to support older clients. Enabled by default. - **serverMetrics** (boolean) - use this option to turn on/off prometheus metrics. - **preHook** (function) - this is a hook if you need to provide any middlewares to express before `unleash` adds any. Express app instance is injected as first argument. diff --git a/lib/options.js b/lib/options.js index 82157ea267..a68a73d4d5 100644 --- a/lib/options.js +++ b/lib/options.js @@ -10,6 +10,7 @@ const DEFAULT_OPTIONS = { databaseSchema: 'public', port: process.env.HTTP_PORT || process.env.PORT || 4242, host: process.env.HTTP_HOST, + pipe: undefined, baseUriPath: process.env.BASE_URI_PATH || '', serverMetrics: true, enableLegacyRoutes: true, @@ -40,6 +41,10 @@ module.exports = { ); } + options.listen = options.pipe + ? { path: options.pipe } + : { port: options.port, host: options.host }; + return options; }, }; diff --git a/lib/server-impl.js b/lib/server-impl.js index 5d35cb92d2..9ec4b3171f 100644 --- a/lib/server-impl.js +++ b/lib/server-impl.js @@ -46,8 +46,8 @@ async function createApp(options) { }); } - const server = app.listen({ port: options.port, host: options.host }, () => - logger.info(`Unleash started on port ${server.address().port}`) + const server = app.listen(options.listen, () => + logger.info('Unleash has started.', server.address()) ); return new Promise((resolve, reject) => {