From 17e70e03dde82adb701b1bbf3054910bce8f4a98 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 26 Jul 2018 12:13:18 -0500 Subject: [PATCH] webserver -- canonicalHost, defaultHost, dockerHostSwap --- lib/modules/webserver/index.js | 3 ++- lib/modules/webserver/server.js | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js index a13fb1b7a..a4dada8a9 100644 --- a/lib/modules/webserver/index.js +++ b/lib/modules/webserver/index.js @@ -1,3 +1,4 @@ +var {canonicalHost} = require('../../utils/host.js'); var utils = require('../../utils/utils.js'); var Server = require('./server.js'); @@ -26,7 +27,7 @@ class WebServer { } setServiceCheck() { - let url = 'http://' + this.host + ':' + this.port; + let url = 'http://' + canonicalHost(this.host) + ':' + this.port; this.events.request("services:register", 'Webserver', function (cb) { utils.checkIsAvailable(url, function (available) { diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index 9f1c64edb..8d9747963 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -1,19 +1,23 @@ let finalhandler = require('finalhandler'); let http = require('http'); let serveStatic = require('serve-static'); +const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host'); require('http-shutdown').extend(); class Server { constructor(options) { this.dist = options.dist || 'dist/'; this.port = options.port || 8000; - this.hostname = options.host || 'localhost'; + this.hostname = dockerHostSwap(options.host) || defaultHost; this.logger = options.logger; } start(callback) { if (this.server && this.server.listening) { - this.logger.warn(__("a webserver is already running at") + " " + ("http://" + this.hostname + ":" + this.port).bold.underline.green); + this.logger.warn(__("a webserver is already running at") + + " " + + ("http://" + canonicalHost(this.hostname) + + ":" + this.port).bold.underline.green); if (callback) { callback(); } @@ -25,7 +29,10 @@ class Server { serve(req, res, finalhandler(req, res)); }).withShutdown(); - this.logger.info(__("webserver available at") + " " + ("http://" + this.hostname + ":" + this.port).bold.underline.green); + this.logger.info(__("webserver available at") + + " " + + ("http://" + canonicalHost(this.hostname) + + ":" + this.port).bold.underline.green); this.server.listen(this.port, this.hostname); if (callback) { callback();