diff --git a/config.js b/config.js index 4c7ca12d..84b6c0df 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 83c5c343..2a175ac7 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 d5996156..e580a523 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("");