move webserver cmds to module

This commit is contained in:
Iuri Matias 2017-12-29 18:29:56 -05:00
parent 411ed41c84
commit 92de2904f1
2 changed files with 17 additions and 6 deletions

View File

@ -43,12 +43,6 @@ class Console {
return text.join('\n');
} else if (['quit', 'exit', 'sair', 'sortir'].indexOf(cmd) >= 0) {
utils.exit();
} else if (cmd === 'webserver start') {
this.events.request("start-webserver");
return " ";
} else if (cmd === 'webserver stop') {
this.events.request("stop-webserver");
return "stopping webserver...";
}
return false;
}

View File

@ -4,6 +4,7 @@ var Server = require('./server.js');
class WebServer {
constructor(embark, options) {
this.embark = embark;
this.logger = embark.logger;
this.events = embark.events;
this.addCheck = options.addCheck;
@ -20,6 +21,7 @@ class WebServer {
this.setServiceCheck();
this.listenToCommands();
this.registerConsoleCommands();
this.server.start();
}
@ -46,6 +48,21 @@ class WebServer {
this.events.setCommandHandler('stop-webserver', () => { this.server.stop(); });
}
registerConsoleCommands() {
const self = this;
self.embark.registerConsoleCommand((cmd, options) => {
if (cmd === 'webserver start') {
self.events.request("start-webserver");
return " ";
}
if (cmd === 'webserver stop') {
self.events.request("stop-webserver");
return "stopping webserver...";
}
return false;
});
}
}
module.exports = WebServer;