mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-24 14:18:57 +00:00
refactor webserver
This commit is contained in:
parent
6d077b1412
commit
76be683ed2
@ -7,7 +7,6 @@ let DeployManager = require('../contracts/deploy_manager.js');
|
|||||||
let CodeGenerator = require('../contracts/code_generator.js');
|
let CodeGenerator = require('../contracts/code_generator.js');
|
||||||
let ServicesMonitor = require('./services_monitor.js');
|
let ServicesMonitor = require('./services_monitor.js');
|
||||||
let Pipeline = require('../pipeline/pipeline.js');
|
let Pipeline = require('../pipeline/pipeline.js');
|
||||||
let Server = require('../pipeline/server.js');
|
|
||||||
let Watch = require('../pipeline/watch.js');
|
let Watch = require('../pipeline/watch.js');
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
@ -36,6 +35,9 @@ class Engine {
|
|||||||
startMonitor() {
|
startMonitor() {
|
||||||
let self = this;
|
let self = this;
|
||||||
if (this.plugins) {
|
if (this.plugins) {
|
||||||
|
// --------
|
||||||
|
// TODO: this only works for services done on startup
|
||||||
|
// --------
|
||||||
let servicePlugins = this.plugins.getPluginsFor('serviceChecks');
|
let servicePlugins = this.plugins.getPluginsFor('serviceChecks');
|
||||||
servicePlugins.forEach(function (plugin) {
|
servicePlugins.forEach(function (plugin) {
|
||||||
plugin.serviceChecks.forEach(function (pluginCheck) {
|
plugin.serviceChecks.forEach(function (pluginCheck) {
|
||||||
@ -161,46 +163,8 @@ class Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
webServerService(options) {
|
webServerService(options) {
|
||||||
let self = this;
|
this.registerModule('webserver', {
|
||||||
let webServerConfig = this.config.webServerConfig;
|
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor)
|
||||||
if (!webServerConfig.enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let host = options.host || webServerConfig.host;
|
|
||||||
let port = options.port || webServerConfig.port;
|
|
||||||
|
|
||||||
this.logger.setStatus("Starting Server");
|
|
||||||
let server = new Server({
|
|
||||||
logger: this.logger,
|
|
||||||
host: host,
|
|
||||||
port: port
|
|
||||||
});
|
|
||||||
|
|
||||||
self.servicesMonitor.addCheck('Webserver', function (cb) {
|
|
||||||
utils.checkIsAvailable('http://' + host + ':' + port, function (available) {
|
|
||||||
let devServer = 'Webserver (http://' + host + ':' + port + ')';
|
|
||||||
if (available) {
|
|
||||||
return cb({name: devServer, status: 'on'});
|
|
||||||
} else {
|
|
||||||
return cb({name: devServer, status: 'off'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
self.events.on('check:wentOffline:Webserver', function () {
|
|
||||||
self.logger.info("Webserver is offline");
|
|
||||||
});
|
|
||||||
|
|
||||||
self.events.setCommandHandler('start-webserver', function() {
|
|
||||||
server.start();
|
|
||||||
});
|
|
||||||
|
|
||||||
self.events.setCommandHandler('stop-webserver', function() {
|
|
||||||
server.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
server.start(function () {
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ Plugin.prototype.registerConsoleCommand = function(cb) {
|
|||||||
this.pluginTypes.push('console');
|
this.pluginTypes.push('console');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: this only works for services done on startup
|
||||||
Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) {
|
Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) {
|
||||||
this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time});
|
this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time});
|
||||||
this.pluginTypes.push('serviceChecks');
|
this.pluginTypes.push('serviceChecks');
|
||||||
|
57
lib/modules/webserver/index.js
Normal file
57
lib/modules/webserver/index.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
var utils = require('../../utils/utils.js');
|
||||||
|
var Server = require('./server.js');
|
||||||
|
|
||||||
|
class WebServer {
|
||||||
|
|
||||||
|
constructor(embark, options) {
|
||||||
|
this.logger = embark.logger;
|
||||||
|
this.events = embark.events;
|
||||||
|
this.addCheck = options.addCheck;
|
||||||
|
|
||||||
|
let self = this;
|
||||||
|
let webServerConfig = embark.config.webServerConfig;
|
||||||
|
if (!webServerConfig.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let host = options.host || webServerConfig.host;
|
||||||
|
let port = options.port || webServerConfig.port;
|
||||||
|
|
||||||
|
this.logger.setStatus("Starting Server");
|
||||||
|
let server = new Server({
|
||||||
|
logger: this.logger,
|
||||||
|
host: host,
|
||||||
|
port: port
|
||||||
|
});
|
||||||
|
|
||||||
|
//embark.registerServiceCheck('WebserverService', function (cb) {
|
||||||
|
this.addCheck('Webserver', function (cb) {
|
||||||
|
utils.checkIsAvailable('http://' + host + ':' + port, function (available) {
|
||||||
|
let devServer = 'Webserver (http://' + host + ':' + port + ')';
|
||||||
|
if (available) {
|
||||||
|
return cb({name: devServer, status: 'on'});
|
||||||
|
} else {
|
||||||
|
return cb({name: devServer, status: 'off'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
self.events.on('check:wentOffline:Webserver', function () {
|
||||||
|
self.logger.info("Webserver is offline");
|
||||||
|
});
|
||||||
|
|
||||||
|
self.events.setCommandHandler('start-webserver', function() {
|
||||||
|
server.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.events.setCommandHandler('stop-webserver', function() {
|
||||||
|
server.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
server.start(function () {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = WebServer;
|
Loading…
x
Reference in New Issue
Block a user