From 92de2904f18f25304e79cef8dff825f8a5d83f95 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 29 Dec 2017 18:29:56 -0500 Subject: [PATCH] move webserver cmds to module --- lib/dashboard/console.js | 6 ------ lib/modules/webserver/index.js | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/dashboard/console.js b/lib/dashboard/console.js index d995a66e0..f6cbcf1b0 100644 --- a/lib/dashboard/console.js +++ b/lib/dashboard/console.js @@ -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; } diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js index 96dea2910..6ac4a958a 100644 --- a/lib/modules/webserver/index.js +++ b/lib/modules/webserver/index.js @@ -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;