Files
homebrewery/server/stream.api.js
T
2026-10-12 21:35:21 +13:00

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;