From 0a573cc3e918e751f5a9e02f5877f7786636539d Mon Sep 17 00:00:00 2001 From: ivanshen Date: Tue, 5 Mar 2019 15:58:03 -0500 Subject: Added live update functionality (feat 8) --- web/routes/sse.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 web/routes/sse.js (limited to 'web/routes/sse.js') diff --git a/web/routes/sse.js b/web/routes/sse.js new file mode 100644 index 0000000..5cd9a3f --- /dev/null +++ b/web/routes/sse.js @@ -0,0 +1,15 @@ +module.exports = function (req, res, next) { + res.sseSetup = function() { + res.writeHead(200, { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache', + 'Connection': 'keep-alive' + }) + } + + res.sseSend = function(data) { + res.write("data: " + JSON.stringify(data) + "\n\n"); + } + + next() +} \ No newline at end of file -- cgit v1.2.3