diff options
| author | Ivan Shen <iwshen11@gmail.com> | 2019-03-05 21:48:34 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-05 21:48:34 +0000 |
| commit | 7ea91f912c1511f60466c3a47ad6ee075cecc0f2 (patch) | |
| tree | 03121db88872a58363eed00703ad57f2151918fd /web/routes/sse.js | |
| parent | b6e80aee2f946949165ef6fcc6f0c433c60123b9 (diff) | |
| parent | a5ff29d43a952ebe2fcc18181a01beda0e5d62d2 (diff) | |
Merge pull request #24 from csc301-winter-2019/feat/8
Add live updates functionality
Diffstat (limited to 'web/routes/sse.js')
| -rw-r--r-- | web/routes/sse.js | 15 |
1 files changed, 15 insertions, 0 deletions
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 |
