From d9d018edc757e1eb1a4e8882ee3b3917fa8b4eae Mon Sep 17 00:00:00 2001 From: crisdias Date: Mon, 16 Mar 2026 20:26:33 -0300 Subject: [PATCH] fix(tinyoffice): connect SSE directly to API, bypass Next.js rewrite Next.js rewrites buffer SSE responses, causing the TinyOffice office view to always show "Disconnected". This makes the EventSource connect directly to the API server on port 3777 instead of going through the Next.js rewrite proxy. Fixes #231 Co-Authored-By: Claude Opus 4.6 (1M context) --- tinyoffice/src/lib/api.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tinyoffice/src/lib/api.ts b/tinyoffice/src/lib/api.ts index 7167c057..2db9e4c5 100644 --- a/tinyoffice/src/lib/api.ts +++ b/tinyoffice/src/lib/api.ts @@ -378,7 +378,12 @@ export function subscribeToEvents( onError?: (err: Event) => void, eventTypes?: string[] ): () => void { - const es = new EventSource(`${API_BASE}/api/events/stream`); + // Connect directly to the API server for SSE, bypassing the Next.js rewrite + // proxy which buffers responses and breaks real-time event streaming. + const sseBase = typeof window !== "undefined" + ? (process.env.NEXT_PUBLIC_SSE_URL ?? `${window.location.protocol}//${window.location.hostname}:3777`) + : ""; + const es = new EventSource(`${sseBase}/api/events/stream`); const handler = (e: MessageEvent) => { try { onEvent(JSON.parse(e.data)); } catch { /* ignore parse errors */ }