From c8c327b6abcfcd41edd3ea8cf81ad449ae99b98f Mon Sep 17 00:00:00 2001 From: karenorman Date: Sat, 1 Feb 2020 20:46:26 +0800 Subject: [PATCH 1/2] Add HTTPS support --- CHANGELOG.md | 5 +++++ config/config.js.sample | 4 ++++ js/server.js | 14 ++++++++++++-- serveronly/index.js | 3 ++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 060abab63f..35d38f15d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/). ❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror² core. +## [2.12.0] - 2020-01-31 + +### Changed +- Add HTTPS support and update config.js.sample + ## [2.11.0] - 2020-01-24 ### Changed diff --git a/config/config.js.sample b/config/config.js.sample index c22960e502..90610106c1 100644 --- a/config/config.js.sample +++ b/config/config.js.sample @@ -21,6 +21,10 @@ var config = { // or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format : // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"], + useHttps: false, // Support HTTPS or not + httpsPrivateKey: "", // HTTPS Private Key path + httpsCertificate: "", // HTTPS Certificate path + language: "en", timeFormat: 24, units: "metric", diff --git a/js/server.js b/js/server.js index b9c9b0d811..19bdfb91bf 100644 --- a/js/server.js +++ b/js/server.js @@ -7,8 +7,6 @@ var express = require("express"); var app = require("express")(); -var server = require("http").Server(app); -var io = require("socket.io")(server); var path = require("path"); var ipfilter = require("express-ipfilter").IpFilter; var fs = require("fs"); @@ -22,6 +20,18 @@ var Server = function(config, callback) { port = process.env.MM_PORT; } + var server = null; + if(config.useHttps){ + var options = { + key: fs.readFileSync(config.httpsPrivateKey), + cert: fs.readFileSync(config.httpsCertificate) + } + server = require("https").Server(options, app); + }else{ + server = require("http").Server(app); + } + var io = require("socket.io")(server); + console.log("Starting server on port " + port + " ... "); server.listen(port, config.address ? config.address : "localhost"); diff --git a/serveronly/index.js b/serveronly/index.js index 3b8013efbe..f7da58f5f4 100644 --- a/serveronly/index.js +++ b/serveronly/index.js @@ -1,5 +1,6 @@ var app = require("../js/app.js"); app.start(function(config) { var bindAddress = config.address ? config.address : "localhost"; - console.log("\nReady to go! Please point your browser to: http://" + bindAddress + ":" + config.port); + var httpType = config.useHttps ? "https" : "http"; + console.log("\nReady to go! Please point your browser to: " + httpType + "://" + bindAddress + ":" + config.port); }); From 5511c15921d15522db6a66e21cbdb30f187201db Mon Sep 17 00:00:00 2001 From: karenorman Date: Wed, 5 Feb 2020 10:23:49 +0800 Subject: [PATCH 2/2] Update description in config.js.sample --- config/config.js.sample | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.js.sample b/config/config.js.sample index 90610106c1..01a41caa89 100644 --- a/config/config.js.sample +++ b/config/config.js.sample @@ -21,9 +21,9 @@ var config = { // or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format : // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"], - useHttps: false, // Support HTTPS or not - httpsPrivateKey: "", // HTTPS Private Key path - httpsCertificate: "", // HTTPS Certificate path + useHttps: false, // Support HTTPS or not, default "false" will use HTTP + httpsPrivateKey: "", // HTTPS private key path, only require when useHttps is true + httpsCertificate: "", // HTTPS Certificate path, only require when useHttps is true language: "en", timeFormat: 24,