diff --git a/lib/dashing.js b/lib/dashing.js index 8a25b4e..0e39314 100644 --- a/lib/dashing.js +++ b/lib/dashing.js @@ -28,6 +28,7 @@ module.exports.Dashing = function Dashing() { dashing.views = dashing.root + '/dashboards'; dashing.default_dashboard = null; dashing.port = (process.env.PORT || 3030); + dashing.force_close_event_socket = false; dashing.protected = function(req, res, next) { next(); @@ -84,14 +85,17 @@ module.exports.Dashing = function Dashing() { // let request last as long as possible req.socket.setTimeout(0); - var conn = { - id: (new Date().getTime().toString() + Math.floor(Math.random() * 1000).toString()), - send: function(body) { - res.write(body); - res.flush(); // need to flush with .compress() - } - }; - connections[conn.id] = conn; + if (!dashing.force_close_event_socket) { + // this won't be necessary if we close the connection after each data package + var conn = { + id: (new Date().getTime().toString() + Math.floor(Math.random() * 1000).toString()), + send: function(body) { + res.write(body); + res.flush(); // need to flush with .compress() + } + }; + connections[conn.id] = conn; + } // send headers for event-stream connection res.writeHead(200, { @@ -105,9 +109,14 @@ module.exports.Dashing = function Dashing() { res.write(latest_events()); res.flush(); // need to flush with .compress() - req.on('close', function() { - delete connections[conn.id]; - }); + if (!dashing.force_close_event_socket) { + req.on('close', function() { + delete connections[conn.id]; + }); + } + else { + res.end(); + } }); app.get('/', function(req, res) {