Import source: app/backend/src/routes/admin-stream
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
import type { FastifyInstance } from 'fastify';
|
||||||
|
import { requireAuth } from '../plugins/session.js';
|
||||||
|
import { publishVisitorCount, setupSse, subscribeRealtime, writeSse } from '../lib/realtime.js';
|
||||||
|
|
||||||
|
export default async function adminStreamRoutes(app: FastifyInstance) {
|
||||||
|
app.get('/api/v1/admin/stream', { preHandler: requireAuth(['admin', 'editor']) }, async (_req, reply) => {
|
||||||
|
setupSse(reply);
|
||||||
|
const data = await publishVisitorCount();
|
||||||
|
writeSse(reply, 'visitor_update', data);
|
||||||
|
await subscribeRealtime(reply, (event) => ['visitor_update', 'activity', 'view_update'].includes(event.event));
|
||||||
|
return reply;
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user