refactor(modules/webserver): use ProcessManager APIs to start and stop the server

This commit is contained in:
Pascal Precht 2018-10-11 15:03:58 +02:00
parent 188a688264
commit 3dd28b9459
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 10 additions and 5 deletions

View File

@ -26,6 +26,11 @@ class WebServer {
this.enableCatchAll = this.webServerConfig.enableCatchAll === true; this.enableCatchAll = this.webServerConfig.enableCatchAll === true;
this.enableCatchAll = false; // FIXME when true, some Requests end up failing (eg: process-logs) this.enableCatchAll = false; // FIXME when true, some Requests end up failing (eg: process-logs)
this.events.request('processes:register', 'webserver', {
launchFn: (cb) => { this.server.start(cb) },
stopFn: (cb) => { this.server.stop(cb) }
});
this.events.emit("status", __("Starting Server")); this.events.emit("status", __("Starting Server"));
this.server = new Server({ this.server = new Server({
@ -52,8 +57,8 @@ class WebServer {
this.server.port = this.port; this.server.port = this.port;
this.testPort(() => { this.testPort(() => {
this.server.stop((_err) => { this.events.request('processes:stop', 'webserver', _err => {
this.server.start((_err, message, port) => { this.events.request('processes:launch', 'webserver', (_err, message, port) => {
this.logger.info(message); this.logger.info(message);
this.port = port; this.port = port;
this.events.request('open-browser', () => {}); this.events.request('open-browser', () => {});
@ -63,7 +68,7 @@ class WebServer {
}); });
this.testPort(() => { this.testPort(() => {
this.server.start((_err, message, port) => { this.events.request('processes:launch', 'webserver', (_err, message, port) => {
this.logger.info(message); this.logger.info(message);
this.port = port; this.port = port;
this.setServiceCheck(); this.setServiceCheck();
@ -108,8 +113,8 @@ class WebServer {
listenToCommands() { listenToCommands() {
this.events.setCommandHandler('build-placeholder', (cb) => this.buildPlaceholderPage(cb)); this.events.setCommandHandler('build-placeholder', (cb) => this.buildPlaceholderPage(cb));
this.events.setCommandHandler('open-browser', (cb) => this.openBrowser(cb)); this.events.setCommandHandler('open-browser', (cb) => this.openBrowser(cb));
this.events.setCommandHandler('start-webserver', (cb) => this.server.start(cb)); this.events.setCommandHandler('start-webserver', (cb) => this.events.request('processes:launch', 'webserver', cb));
this.events.setCommandHandler('stop-webserver', (cb) => this.server.stop(cb)); this.events.setCommandHandler('stop-webserver', (cb) => this.events.request('processes:stop', 'webserver', cb));
this.events.setCommandHandler('logs:webserver:turnOn', (cb) => this.server.enableLogging(cb)); this.events.setCommandHandler('logs:webserver:turnOn', (cb) => this.server.enableLogging(cb));
this.events.setCommandHandler('logs:webserver:turnOff', (cb) => this.server.disableLogging(cb)); this.events.setCommandHandler('logs:webserver:turnOff', (cb) => this.server.disableLogging(cb));
} }