Merge pull request #738 from embark-framework/bug_fix/double-embark

Enable multiple Embark runs at the same time
This commit is contained in:
Iuri Matias 2018-08-24 10:09:45 -04:00 committed by GitHub
commit eb57b358cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 13 deletions

View File

@ -17,20 +17,36 @@ class WebServer {
this.port = options.port || this.webServerConfig.port;
this.events.emit("status", __("Starting Server"));
this.server = new Server({host: this.host, port: this.port});
this.testPort(() => {
this.listenToCommands();
this.registerConsoleCommands();
this.server.start((_err, message, port) => {
this.logger.info(message);
this.port = port;
this.setServiceCheck();
});
});
}
this.setServiceCheck();
this.listenToCommands();
this.registerConsoleCommands();
let self = this;
this.server.start((_err, message) => self.logger.info(message));
testPort(done) {
utils.pingEndpoint(this.host, this.port, 'http', 'http', '', (err) => {
if (err) { // Port is ok
return done();
}
this.logger.warn(__('Webserver already running on port %s. Assigning an available port', this.port));
this.port = 0;
this.server.port = 0;
done();
});
}
setServiceCheck() {
let url = 'http://' + canonicalHost(this.host) + ':' + this.port;
const self = this;
this.events.request("services:register", 'Webserver', function (cb) {
let url = 'http://' + canonicalHost(self.host) + ':' + self.port;
utils.checkIsAvailable(url, function (available) {
let devServer = __('Webserver') + ' (' + url + ')';
let serverStatus = (available ? 'on' : 'off');

View File

@ -24,12 +24,14 @@ class Server {
serve(req, res, finalhandler(req, res));
}).withShutdown();
let message = __("webserver available at") +
" " +
("http://" + canonicalHost(this.hostname) +
":" + this.port).bold.underline.green;
this.server.listen(this.port, this.hostname);
callback(null, message);
this.server.listen(this.port, this.hostname, () => {
this.port = this.server.address().port;
callback(null, __("webserver available at") +
" " +
("http://" + canonicalHost(this.hostname) +
":" + this.port).bold.underline.green, this.port);
});
}
stop(callback) {