diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index d10c9165..fcd0a83c 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -6,6 +6,8 @@ const express = require('express'); const fs = require('../../core/fs'); require('http-shutdown').extend(); +const WEB_SOCKET_STATE_OPEN = 1; + class Server { constructor(options) { this.buildDir = options.buildDir; @@ -31,15 +33,17 @@ class Server { const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']}); this.app = express(); + expressWebSocket(this.app); + this.app.use(main); this.app.use('/coverage', coverage); this.app.use(coverageStyle); - expressWebSocket(this.app); - this.app.ws('/', function(ws, _req) { self.events.on('outputDone', () => { - ws.send('outputDone'); + if (ws.readyState === WEB_SOCKET_STATE_OPEN) { + ws.send('outputDone'); + } }); });