mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 20:29:01 +00:00
23 lines
512 B
JavaScript
23 lines
512 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'
|
|
});
|
|
|
|
const subId = Stream.subscribe(req.params.id, res);
|
|
|
|
res.on('close', ()=>{
|
|
Stream.unsubscribe(subId);
|
|
});
|
|
});
|
|
|
|
export default app; |