Add HTTPS support

This commit is contained in:
karenorman 2020-02-01 20:46:26 +08:00
parent 4c2a9b47f5
commit c8c327b6ab
4 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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",

View File

@ -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");

View File

@ -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);
});