diff --git a/src/lib/core/config.js b/src/lib/core/config.js index 26a4c1199..43c70d35b 100644 --- a/src/lib/core/config.js +++ b/src/lib/core/config.js @@ -483,6 +483,8 @@ Config.prototype.loadWebServerConfigFile = function() { }; webServerConfig.protocol = 'https'; } catch (e) { + this.logger.error(e.message); + this.logger.warn('Invalid path for key/cert in config/webserver.js. Using http instead.'); webServerConfig.certOptions = {}; webServerConfig.protocol = 'http'; } diff --git a/src/lib/modules/webserver/index.js b/src/lib/modules/webserver/index.js index d023bcd37..92ca03fe3 100644 --- a/src/lib/modules/webserver/index.js +++ b/src/lib/modules/webserver/index.js @@ -100,7 +100,7 @@ class WebServer { const self = this; this.events.request("services:register", 'Webserver', function (cb) { - let url = this.protocol + '://' + canonicalHost(self.host) + ':' + self.port; + let url = self.protocol + '://' + canonicalHost(self.host) + ':' + self.port; utils.checkIsAvailable(url, function (available) { let devServer = __('Webserver') + ' (' + url + ')'; let serverStatus = (available ? 'on' : 'off'); diff --git a/src/lib/utils/utils.js b/src/lib/utils/utils.js index 513579d48..5c5e10eba 100644 --- a/src/lib/utils/utils.js +++ b/src/lib/utils/utils.js @@ -32,19 +32,13 @@ function recursiveMerge(target, source) { function checkIsAvailable(url, callback) { const protocol = url.split(':')[0]; - if (protocol === 'http') { - http.get(url, function (_res) { - callback(true); - }).on('error', function (_res) { - callback(false); - }); - } else if (protocol === 'https') { - https.get(url, function (_res) { - callback(true); - }).on('error', function (_res) { - callback(false); - }); - } + const httpObj = (protocol === 'https') ? https : http; + + httpObj.get(url, function (_res) { + callback(true); + }).on('error', function (_res) { + callback(false); + }); } function httpGetRequest(httpObj, url, callback) {