warn if server is already running or not

This commit is contained in:
Iuri Matias 2017-12-17 19:18:35 -05:00
parent 14d330a729
commit 8360295ed0
1 changed files with 14 additions and 0 deletions

View File

@ -12,6 +12,13 @@ class Server {
} }
start(callback) { 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);
if (callback) {
callback();
}
return;
}
let serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']}); let serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']});
this.server = http.createServer(function onRequest(req, res) { this.server = http.createServer(function onRequest(req, res) {
@ -26,6 +33,13 @@ class Server {
} }
stop(callback) { stop(callback) {
if (!this.server || !this.server.listening) {
this.logger.warn("no webserver is currently running");
if (callback) {
callback();
}
return;
}
this.server.shutdown(function() { this.server.shutdown(function() {
if (callback) { if (callback) {
callback(); callback();