Skip to content

Commit

Permalink
Merge pull request thelounge#1479 from thelounge/xpaw/unix-socket
Browse files Browse the repository at this point in the history
Add support for binding to unix sockets
  • Loading branch information
xPaw authored Sep 1, 2017
2 parents f65fb65 + b79a6cc commit 9e1296d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions defaults/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
36 changes: 24 additions & 12 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

log.info(
"Available at " +
colors.green(`${protocol}://${address.address}:${address.port}/`) +
` in ${colors.bold(config.public ? "public" : "private")} mode`
);
let listenParams;

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,
Expand Down

0 comments on commit 9e1296d

Please sign in to comment.