Skip to content

Commit

Permalink
Merge pull request thelounge#284 from maxpoulin64/tilde
Browse files Browse the repository at this point in the history
Add support for ~ home folder expansion
  • Loading branch information
xPaw committed Apr 27, 2016
2 parents 12c88de + 1d49bda commit d6f20a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/helper.js
Original file line number Diff line number Diff line change
@@ -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");
}

4 changes: 2 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit d6f20a6

Please sign in to comment.