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.
This commit is contained in:
Duc Nguyen
2026-07-23 16:02:01 +07:00
committed by decolua
parent 53a8b5ed55
commit 57b3b2c175
2 changed files with 8 additions and 1 deletions

View File

@@ -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",
},
});
}

6
src/instrumentation.js Normal file
View File

@@ -0,0 +1,6 @@
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
const { initConsoleLogCapture } = await import("@/lib/consoleLogBuffer");
initConsoleLogCapture();
}
}