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 utils = require('../../utils/utils.js');
|
||||||
var Server = require('./server.js');
|
var Server = require('./server.js');
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ class WebServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
setServiceCheck() {
|
setServiceCheck() {
|
||||||
let url = 'http://' + this.host + ':' + this.port;
|
let url = 'http://' + canonicalHost(this.host) + ':' + this.port;
|
||||||
|
|
||||||
this.events.request("services:register", 'Webserver', function (cb) {
|
this.events.request("services:register", 'Webserver', function (cb) {
|
||||||
utils.checkIsAvailable(url, function (available) {
|
utils.checkIsAvailable(url, function (available) {
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
let finalhandler = require('finalhandler');
|
let finalhandler = require('finalhandler');
|
||||||
let http = require('http');
|
let http = require('http');
|
||||||
let serveStatic = require('serve-static');
|
let serveStatic = require('serve-static');
|
||||||
|
const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host');
|
||||||
require('http-shutdown').extend();
|
require('http-shutdown').extend();
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.dist = options.dist || 'dist/';
|
this.dist = options.dist || 'dist/';
|
||||||
this.port = options.port || 8000;
|
this.port = options.port || 8000;
|
||||||
this.hostname = options.host || 'localhost';
|
this.hostname = dockerHostSwap(options.host) || defaultHost;
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
start(callback) {
|
start(callback) {
|
||||||
if (this.server && this.server.listening) {
|
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) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
@ -25,7 +29,10 @@ class Server {
|
||||||
serve(req, res, finalhandler(req, res));
|
serve(req, res, finalhandler(req, res));
|
||||||
}).withShutdown();
|
}).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);
|
this.server.listen(this.port, this.hostname);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
|
|
Loading…
Reference in New Issue