From 3e22b6e88a5501229b8e92b4158d0c4b490d9700 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Fri, 26 Sep 2014 16:26:21 -0700 Subject: [PATCH] Added https support --- config.js | 34 ++++++++++++++++++++++++++++++++++ package.json | 2 +- src/server.js | 22 ++++++++++++++++++---- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/config.js b/config.js index 4c7ca12..84b6c0d 100644 --- a/config.js +++ b/config.js @@ -159,5 +159,39 @@ module.exports = { // @default "#foo, #shout-irc" // join: "#foo, #shout-irc" + }, + + // + // Run Shout with HTTPS support. + // + // @type object + // @default {} + // + https: { + // + // Enable HTTPS support. + // + // @type boolean + // @default false + // + enable: false, + + // + // Path to the key. + // + // @type string + // @example "sslcert/key.pem" + // @default "" + // + key: "", + + // + // Path to the certificate. + // + // @type string + // @example "sslcert/key-cert.pem" + // @default "" + // + certificate: "" } }; diff --git a/package.json b/package.json index 83c5c34..2a175ac 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "shout", "description": "The self-hosted web IRC client", - "version": "0.36.0", + "version": "0.37.0", "author": "Mattias Erming", "preferGlobal": true, "bin": { diff --git a/src/server.js b/src/server.js index d599615..e580a52 100644 --- a/src/server.js +++ b/src/server.js @@ -19,10 +19,24 @@ module.exports = function(port, host, isPublic) { var app = express() .use(index) .use(express.static("client")) - .use(express.static(Helper.resolveHomePath("cache"))) - .listen(config.port, config.host); + .use(express.static(Helper.resolveHomePath("cache"))); - sockets = io(app); + var server = null; + var https = config.https || {}; + var protocol = https.enable ? "https" : "http"; + + if (!https.enable){ + server = require("http"); + server = server.createServer(app).listen(port, host); + } else { + server = require("https"); + server = server.createServer({ + key: fs.readFileSync(https.key), + cert: fs.readFileSync(https.certificate) + }, app).listen(port, host) + } + + sockets = io(server); sockets.on("connect", function(socket) { if (config.public) { auth.call(socket); @@ -34,7 +48,7 @@ module.exports = function(port, host, isPublic) { manager.sockets = sockets; console.log(""); - console.log("Shout is now running on http://" + config.host + ":" + config.port + "/"); + console.log("Shout is now running on " + protocol + "://" + config.host + ":" + config.port + "/"); console.log("Press ctrl-c to stop"); console.log("");