mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 22:38:43 +00:00
24 lines
581 B
JavaScript
24 lines
581 B
JavaScript
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, req.query?.client);
|
|
});
|
|
|
|
app.get('/api/stream/unsubscribe/:id', (req, res)=>{
|
|
Stream.unsubscribe(req.params?.id);
|
|
res.status(200).send();
|
|
});
|
|
|
|
export default app; |