From 3b36b1ad459ee739a87a32a18bb5846770125bec Mon Sep 17 00:00:00 2001 From: ivanshen Date: Tue, 5 Mar 2019 16:39:35 -0500 Subject: modularize plot points --- web/routes/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'web/routes') diff --git a/web/routes/index.js b/web/routes/index.js index 885724d..b2ba91f 100644 --- a/web/routes/index.js +++ b/web/routes/index.js @@ -36,6 +36,7 @@ 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); } @@ -48,8 +49,11 @@ router.post('/mobilerequest', function(req, res) { router.get('/stream', function(req, res){ - res.sseSetup() + // 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; -- cgit v1.2.3