Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
Blame · Line-by-line history

events.ts

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

events.tsBlame39 lines · 1 contributor
6522084Claude1/**
2 * SSE event stream routes — real-time updates for gate runs, PRs, and notifications.
3 *
4 * GET /api/events/stream?channels=gate:repoId,pr:prId,notification
5 */
6
7import { Hono } from "hono";
8import { softAuth } from "../middleware/auth";
9import type { AuthEnv } from "../middleware/auth";
10import { createSSEStream, getActiveConnections } from "../lib/sse";
11
12const events = new Hono<AuthEnv>();
13
14events.get("/api/events/stream", softAuth, (c) => {
15 const user = c.get("user");
16 const channelParam = c.req.query("channels") || "";
17 const requestedChannels = channelParam
18 .split(",")
19 .map((ch) => ch.trim())
20 .filter(Boolean);
21
22 if (requestedChannels.length === 0) {
23 return c.json({ error: "No channels specified" }, 400);
24 }
25
26 // Auto-add user-specific notification channel if authenticated
27 const channels = [...requestedChannels];
28 if (user && !channels.some((ch) => ch.startsWith("notification"))) {
29 channels.push(`notification:${user.id}`);
30 }
31
32 return createSSEStream(channels, user?.id);
33});
34
35events.get("/api/events/health", (c) => {
36 return c.json({ connections: getActiveConnections() });
37});
38
39export default events;