Move Stream routes to seperate API file

This commit is contained in:
G.Ambatte
2026-10-11 12:08:07 +13:00
parent 5d494c8435
commit c60740092b
2 changed files with 26 additions and 13 deletions
+24
View File
@@ -0,0 +1,24 @@
import express from 'express';
import Stream from './eventStreamSource.js';
const app = express.Router();
// Create Event Stream source for pages to listen to
app.get('/api/stream/:id', (req, res)=>{
res.writeHead(200, {
'Content-Type' : 'text/event-stream',
'Cache-Control' : 'no-cache',
'Connection' : 'keep-alive',
'Content-Encoding' : 'none'
});
;
Stream.subscribe(req.params.id, res);
});
app.get('/api/stream/unsubscribe/:id', (req, res)=>{
Stream.unsubscribe(req.params?.id);
res.status(200).send();
});
export default app;