Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTPS Magicmirror (resubmit) #1915

Merged
merged 3 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});