From 57b3b2c175b00a82a27bfec8f14a77b99a387ceb Mon Sep 17 00:00:00 2001 From: Duc Nguyen Date: Thu, 23 Jul 2026 16:02:01 +0700 Subject: [PATCH] fix(console-log): initialize capture at server boot + prevent SSE proxy buffering Initialize initConsoleLogCapture() via Next.js instrumentation register() hook so logs are captured from startup in headless/Docker deployments, and add X-Accel-Buffering/Cache-Control headers to the SSE stream route to prevent reverse proxies from buffering the initial payload. --- src/app/api/translator/console-logs/stream/route.js | 3 ++- src/instrumentation.js | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/instrumentation.js diff --git a/src/app/api/translator/console-logs/stream/route.js b/src/app/api/translator/console-logs/stream/route.js index 5eb3ae37..51ed3702 100644 --- a/src/app/api/translator/console-logs/stream/route.js +++ b/src/app/api/translator/console-logs/stream/route.js @@ -83,8 +83,9 @@ export async function GET(request) { return new Response(stream, { headers: { "Content-Type": "text/event-stream", - "Cache-Control": "no-cache", + "Cache-Control": "no-cache, no-transform", "Connection": "keep-alive", + "X-Accel-Buffering": "no", }, }); } diff --git a/src/instrumentation.js b/src/instrumentation.js new file mode 100644 index 00000000..f511eae2 --- /dev/null +++ b/src/instrumentation.js @@ -0,0 +1,6 @@ +export async function register() { + if (process.env.NEXT_RUNTIME === "nodejs") { + const { initConsoleLogCapture } = await import("@/lib/consoleLogBuffer"); + initConsoleLogCapture(); + } +}