From 925ae068b092d767ce3609a45c428be0f93ad80f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 26 Feb 2018 17:44:09 -0500 Subject: [PATCH] send logs to ws --- lib/modules/webserver/backend/index.html | 33 ++++++++++-------------- lib/modules/webserver/index.js | 2 +- lib/modules/webserver/server.js | 14 +++++----- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/modules/webserver/backend/index.html b/lib/modules/webserver/backend/index.html index 43288c26..3deda358 100644 --- a/lib/modules/webserver/backend/index.html +++ b/lib/modules/webserver/backend/index.html @@ -1,29 +1,22 @@ Welcome to Embark! diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js index a13fb1b7..40246a50 100644 --- a/lib/modules/webserver/index.js +++ b/lib/modules/webserver/index.js @@ -16,7 +16,7 @@ class WebServer { this.port = options.port || this.webServerConfig.port; this.events.emit("status", __("Starting Server")); - this.server = new Server({logger: this.logger, host: this.host, port: this.port}); + this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events}); this.setServiceCheck(); this.listenToCommands(); diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index 548001d7..b72912d7 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -8,6 +8,7 @@ var expressWebSocket = require('express-ws'); class Server { constructor(options) { + this.events = options.events; this.dist = options.dist || 'dist/'; this.port = options.port || 8000; this.hostname = options.host || 'localhost'; @@ -28,14 +29,13 @@ class Server { var app = express(); app.use(serve); - app.use('/backend', serveStatic(path.join(__dirname, 'backend'), {'backend': ['index.html', 'index.htm']})); + app.use('/embark', serveStatic(path.join(__dirname, 'backend'), {'backend': ['index.html', 'index.htm']})); expressWebSocket(app); - app.ws('/logs', function(ws, req) { + app.ws('/embark/logs', function(ws, req) { self.events.on("log", function(logLevel, logMsg) { - console.dir("got message " + logMsg); - ws.send(logMsg); + ws.send(logMsg.stripColors); }); ws.on('message', function(msg) { console.dir("got message"); @@ -44,9 +44,9 @@ class Server { }); }); - //app.get('/embark', function (req, res) { - // res.send('Welcome to Embark') - //}); + app.get('/embark', function (req, res) { + res.send('Welcome to Embark') + }); app.listen(this.port);