add webserver start/stop cmd

This commit is contained in:
Iuri Matias 2017-12-17 18:34:41 -05:00
parent 9efd29ec9e
commit 113bb25142
6 changed files with 39 additions and 5 deletions

View File

@ -182,6 +182,14 @@ class Engine {
return cb({name: devServer, status: 'on'});
});
self.events.setCommandHandler('start-webserver', function() {
server.start();
});
self.events.setCommandHandler('stop-webserver', function() {
server.stop();
});
server.start(function () {
});
}

View File

@ -3,6 +3,7 @@ let RunCode = require('../core/runCode.js');
class Console {
constructor(options) {
this.events = options.events;
this.plugins = options.plugins;
this.version = options.version;
this.contractsConfig = options.contractsConfig;
@ -42,6 +43,12 @@ 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 "starting webserver...";
} else if (cmd === 'webserver stop') {
this.events.request("stop-webserver");
return "stopping webserver...";
}
return false;
}

View File

@ -6,6 +6,7 @@ let Console = require('./console.js');
class Dashboard {
constructor(options) {
this.logger = options.logger;
this.events = options.events;
this.plugins = options.plugins;
this.version = options.version;
this.env = options.env;
@ -18,7 +19,12 @@ class Dashboard {
async.waterfall([
function startConsole(callback) {
console = new Console({plugins: self.plugins, version: self.version, contractsConfig: self.contractsConfig});
console = new Console({
events: self.events,
plugins: self.plugins,
version: self.version,
contractsConfig: self.contractsConfig
});
callback();
},
function startMonitor(callback) {

View File

@ -71,6 +71,7 @@ class Embark {
}
let dashboard = new Dashboard({
events: engine.events,
logger: engine.logger,
plugins: engine.plugins,
version: self.version,

View File

@ -1,6 +1,7 @@
let finalhandler = require('finalhandler');
let http = require('http');
let serveStatic = require('serve-static');
require('http-shutdown').extend();
class Server {
constructor(options) {
@ -13,13 +14,23 @@ class Server {
start(callback) {
let serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']});
let server = http.createServer(function onRequest(req, res) {
this.server = http.createServer(function onRequest(req, res) {
serve(req, res, finalhandler(req, res));
});
}).withShutdown();
this.logger.info("webserver available at " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
server.listen(this.port, this.hostname);
callback();
this.server.listen(this.port, this.hostname);
if (callback) {
callback();
}
}
stop(callback) {
this.server.shutdown(function() {
if (callback) {
callback();
}
});
}
}

View File

@ -34,6 +34,7 @@
"follow-redirects": "^1.2.4",
"fs-extra": "^2.0.0",
"globule": "^1.1.0",
"http-shutdown": "^1.2.0",
"ipfs-api": "17.2.4",
"merge": "^1.2.0",
"mocha": "^2.2.5",