Skip to content

Commit

Permalink
Merge pull request MagicMirrorOrg#1915 from normankong/develop
Browse files Browse the repository at this point in the history
Support HTTPS Magicmirror (resubmit)
  • Loading branch information
MichMich authored Feb 6, 2020
2 parents e5cdcd1 + 89c9d4d commit 30e93a9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added the ability to hide the temp label and weather icon in the `currentweather` module to allow showing only information such as wind and sunset/rise.
- The `clock` module now optionally displays sun and moon data, including rise/set times, remaining daylight, and percent of moon illumination.
- Added Hebrew translation.
- Add HTTPS support and update config.js.sample


### Fixed
- Force declaration of public ip adress in config file (ISSUE #1852)
Expand Down
4 changes: 4 additions & 0 deletions config/config.js.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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,
units: "metric",
Expand Down
14 changes: 12 additions & 2 deletions js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion serveronly/index.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 30e93a9

Please sign in to comment.