From b79a6cce0cbca1cefd386a9e919b995375cfd2e1 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 31 Aug 2017 21:56:20 +0300 Subject: [PATCH] Add support for binding to unix sockets Fixes #686. Fixes #691. --- defaults/config.js | 2 ++ src/server.js | 34 +++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/defaults/config.js b/defaults/config.js index e3e728eb..d9df8881 100644 --- a/defaults/config.js +++ b/defaults/config.js @@ -16,6 +16,8 @@ module.exports = { // IP address or hostname for the web server to listen on. // Setting this to undefined will listen on all interfaces. // + // For UNIX domain sockets, use unix:/absolute/path/to/file.sock. + // // @type string // @default undefined // diff --git a/src/server.js b/src/server.js index 6eb6ee7d..6fcec567 100644 --- a/src/server.js +++ b/src/server.js @@ -83,18 +83,30 @@ module.exports = function() { }, app); } - server.listen({ - port: config.port, - host: config.host, - }, () => { - const protocol = config.https.enable ? "https" : "http"; - var address = server.address(); + let listenParams; - log.info( - "Available at " + - colors.green(`${protocol}://${address.address}:${address.port}/`) + - ` in ${colors.bold(config.public ? "public" : "private")} mode` - ); + if (typeof config.host === "string" && config.host.startsWith("unix:")) { + listenParams = config.host.replace(/^unix:/, ""); + } else { + listenParams = { + port: config.port, + host: config.host, + }; + } + + server.listen(listenParams, () => { + if (typeof listenParams === "string") { + log.info("Available on socket " + colors.green(listenParams)); + } else { + const protocol = config.https.enable ? "https" : "http"; + const address = server.address(); + + log.info( + "Available at " + + colors.green(`${protocol}://${address.address}:${address.port}/`) + + ` in ${colors.bold(config.public ? "public" : "private")} mode` + ); + } const sockets = io(server, { serveClient: false,