From 749c6f391eb1e66169d52fd010ea36f068b55987 Mon Sep 17 00:00:00 2001 From: M1 Date: Tue, 17 Mar 2026 06:59:43 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20SSE=20stream=20500=20=E2=80=94=20replace?= =?UTF-8?q?=20error()=20with=20plain=20Response=20in=20stream=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/src/routes/pings.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/web/src/routes/pings.ts b/apps/web/src/routes/pings.ts index a211064..de8fbec 100644 --- a/apps/web/src/routes/pings.ts +++ b/apps/web/src/routes/pings.ts @@ -86,27 +86,24 @@ export const ingest = new Elysia() }) // SSE: stream live pings — auth via Bearer header or cookie - .get("/monitors/:id/stream", async ({ params, headers, cookie, error }) => { - // Case-insensitive bearer parsing + .get("/monitors/:id/stream", async ({ params, headers, cookie }) => { const authHeader = headers["authorization"] ?? ""; const bearer = authHeader.match(/^bearer\s+(.+)$/i)?.[1]?.trim(); const key = bearer ?? cookie?.pingql_key?.value; - if (!key) return error(401, { error: "Unauthorized" }); + if (!key) return new Response(JSON.stringify({ error: "Unauthorized" }), { status: 401 }); const resolved = await resolveKey(key); - if (!resolved) return error(401, { error: "Unauthorized" }); + if (!resolved) return new Response(JSON.stringify({ error: "Unauthorized" }), { status: 401 }); - // Verify ownership const [monitor] = await sql` SELECT id FROM monitors WHERE id = ${params.id} AND account_id = ${resolved.accountId} `; - if (!monitor) return error(404, { error: "Not found" }); + if (!monitor) return new Response(JSON.stringify({ error: "Not found" }), { status: 404 }); - // SSE connection limit per monitor const limit = Number(process.env.MAX_SSE_PER_MONITOR ?? 10); if ((bus.get(params.id)?.size ?? 0) >= limit) { - return error(429, { error: "Too many connections for this monitor" }); + return new Response(JSON.stringify({ error: "Too many connections for this monitor" }), { status: 429 }); } return makeSSEStream(params.id);