diff --git a/lib/modules/webserver/backend/index.html b/lib/modules/webserver/backend/index.html index 01d3caf4..43288c26 100644 --- a/lib/modules/webserver/backend/index.html +++ b/lib/modules/webserver/backend/index.html @@ -1 +1,29 @@ Welcome to Embark! + + + diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index 7be27eb0..bacc6c83 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -5,6 +5,7 @@ const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host') require('http-shutdown').extend(); var express = require('express'); let path = require('path'); +var expressWebSocket = require('express-ws'); class Server { constructor(options) { @@ -14,6 +15,7 @@ class Server { } start(callback) { + const self = this; if (this.server && this.server.listening) { let message = __("a webserver is already running at") + " " + ("http://" + canonicalHost(this.hostname) + @@ -27,6 +29,20 @@ class Server { app.use(serve); app.use('/backend', serveStatic(path.join(__dirname, 'backend'), {'backend': ['index.html', 'index.htm']})); + expressWebSocket(app); + + app.ws('/logs', function(ws, req) { + self.events.on("log", function(logLevel, logMsg) { + console.dir("got message " + logMsg); + ws.send(logMsg); + }); + ws.on('message', function(msg) { + console.dir("got message"); + console.dir(msg); + ws.send(msg); + }); + }); + //app.get('/embark', function (req, res) { // res.send('Welcome to Embark') //}); diff --git a/package.json b/package.json index d139c5bc..6e6ce69f 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "eth-lib": "^0.2.8", "ethereumjs-wallet": "0.6.0", "express": "^4.16.2", + "express-ws": "^3.0.0", "file-loader": "^1.1.5", "finalhandler": "^1.1.1", "follow-redirects": "^1.2.4",