From 96d180077cf74224b53036a8b3a1591c6a47f702 Mon Sep 17 00:00:00 2001 From: Maxime Poulin Date: Wed, 27 Apr 2016 04:13:25 -0400 Subject: [PATCH] Add support for ~ home folder expansion --- src/helper.js | 21 ++++++++++++++++++++- src/server.js | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/helper.js b/src/helper.js index ea7666e7..38ab2596 100644 --- a/src/helper.js +++ b/src/helper.js @@ -1,10 +1,29 @@ var path = require("path"); +var os = require("os"); module.exports = { HOME: (process.env.HOME || process.env.USERPROFILE) + "/.lounge", - getConfig: getConfig + getConfig: getConfig, + expandHome: expandHome, }; function getConfig() { return require(path.resolve(this.HOME) + "/config"); } + +function expandHome(path) { + var home; + + if (os.homedir) { + home = os.homedir(); + } + + if (!home) { + home = process.env.HOME || ""; + } + + home = home.replace("$", "$$$$"); + + return path.replace(/^~($|\/|\\)/, home + "$1"); +} + diff --git a/src/server.js b/src/server.js index 895e7312..57bfe624 100644 --- a/src/server.js +++ b/src/server.js @@ -33,8 +33,8 @@ module.exports = function(options) { } else { server = require("spdy"); server = server.createServer({ - key: fs.readFileSync(https.key), - cert: fs.readFileSync(https.certificate) + key: fs.readFileSync(Helper.expandHome(https.key)), + cert: fs.readFileSync(Helper.expandHome(https.certificate)) }, app).listen(port, host); }