mirror of https://github.com/embarklabs/embark.git
webserver -- canonicalHost, defaultHost, dockerHostSwap
This commit is contained in:
parent
d70264adb6
commit
0191ec9d24
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue