aboutsummaryrefslogtreecommitdiff
path: root/web/routes/index.js
diff options
context:
space:
mode:
authorIvan Shen <iwshen11@gmail.com>2019-03-05 21:48:34 +0000
committerGitHub <noreply@github.com>2019-03-05 21:48:34 +0000
commit7ea91f912c1511f60466c3a47ad6ee075cecc0f2 (patch)
tree03121db88872a58363eed00703ad57f2151918fd /web/routes/index.js
parentb6e80aee2f946949165ef6fcc6f0c433c60123b9 (diff)
parenta5ff29d43a952ebe2fcc18181a01beda0e5d62d2 (diff)
Merge pull request #24 from csc301-winter-2019/feat/8
Add live updates functionality
Diffstat (limited to 'web/routes/index.js')
-rw-r--r--web/routes/index.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/web/routes/index.js b/web/routes/index.js
index b2d0796..b2ba91f 100644
--- a/web/routes/index.js
+++ b/web/routes/index.js
@@ -2,7 +2,7 @@ var express = require('express');
var router = express.Router();
var Mockpoints = require('../models/mockpoints');
var Points = require('../models/points');
-
+const connections = [];
/* GET home page. */
router.get('/', function(req, res, next) {
// for now just redirect to /map
@@ -36,10 +36,24 @@ router.post('/mobilerequest', function(req, res) {
console.log(`err inserting mobile request into db: ${err}`);
res.status(500).send({ error: "boo:(" });
} else {
+ // send event to all connections
+ for(var i = 0; i < connections.length; i++) {
+ connections[i].sseSend(data);
+ }
console.log(result);
res.status(200).send({'status': 'success', 'data': data});
}
});
+
});
+
+router.get('/stream', function(req, res){
+ // set up server side event (communication line between front end and server)
+ res.sseSetup();
+ // send an event to the front end to open the connection
+ res.sseSend('ok');
+ // push connection to connection array
+ connections.push(res);
+});
module.exports = router;