add https support

This commit is contained in:
Andre 2020-03-28 12:37:50 +01:00
parent 39cb582e07
commit 351e0f3a0b
3 changed files with 17 additions and 3 deletions

View File

@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Run tests on long term support and latest stable version of nodejs
- Added the ability to configure a list of modules that shouldn't be update checked.
- Run linters on git commits
- Add HTTPS support for clientonly-mode.
### Fixed
- Force declaration of public ip address in config file (ISSUE #1852)

View File

@ -18,6 +18,9 @@
["address", "port"].forEach((key) => {
config[key] = getCommandLineParameter(key, process.env[key.toUpperCase()]);
});
// determine if "--use-tls"-flag was provided
config["tls"] = process.argv.indexOf(`--use-tls`) > 0;
}
function getServerConfig(url) {
@ -48,7 +51,7 @@
if (message !== undefined && typeof message === "string") {
console.log(message);
} else {
console.log("Usage: 'node clientonly --address 192.168.1.10 --port 8080'");
console.log("Usage: 'node clientonly --address 192.168.1.10 --port 8080 [--use-tls]'");
}
process.exit(code);
}
@ -56,16 +59,18 @@
getServerAddress();
(config.address && config.port) || fail();
var prefix = config.tls ? "https://" : "http://";
// Only start the client if a non-local server was provided
if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].indexOf(config.address) === -1) {
getServerConfig(`http://${config.address}:${config.port}/config/`)
getServerConfig(`${prefix}${config.address}:${config.port}/config/`)
.then(function (configReturn) {
// Pass along the server config via an environment variable
var env = Object.create(process.env);
var options = { env: env };
configReturn.address = config.address;
configReturn.port = config.port;
configReturn.tls = config.tls;
env.config = JSON.stringify(configReturn);
// Spawn electron application

View File

@ -45,8 +45,16 @@ function createWindow() {
// and load the index.html of the app.
// If config.address is not defined or is an empty string (listening on all interfaces), connect to localhost
var prefix;
if (config["tls"] !== null && config["tls"]) {
prefix = 'https://';
} else {
prefix = 'http://';
}
var address = (config.address === void 0) | (config.address === "") ? (config.address = "localhost") : config.address;
mainWindow.loadURL(`http://${address}:${config.port}`);
mainWindow.loadURL(`${prefix}${address}:${config.port}`);
// Open the DevTools if run with "npm start dev"
if (process.argv.includes("dev")) {