diff --git a/backend/src/routes/import.ts b/backend/src/routes/import.ts index ac46011..4727ea7 100644 --- a/backend/src/routes/import.ts +++ b/backend/src/routes/import.ts @@ -28,17 +28,14 @@ function isJsonFile(file: { mimetype: string; originalname: string }): boolean { ); } -function sseWrite(res: import('express').Response, data: Record) { - res.write(`data: ${JSON.stringify(data)}\n\n`); -} +const SSE_PAD_TARGET = 4096; -/** - * Send a 2 KB comment block to push past any proxy buffering threshold. - * Nginx and other reverse proxies often buffer the first few KB before - * starting to stream — this padding forces the initial flush. - */ -function ssePadding(res: import('express').Response) { - res.write(`: ${' '.repeat(2048)}\n\n`); +function sseWrite(res: import('express').Response, data: Record) { + const payload = `data: ${JSON.stringify(data)}\n\n`; + const pad = Math.max(0, SSE_PAD_TARGET - payload.length); + // SSE comment lines (": ...") are ignored by the browser but push + // data past proxy buffer thresholds so each event is delivered immediately. + res.write(pad > 0 ? `: ${' '.repeat(pad)}\n${payload}` : payload); } const router = Router(); @@ -71,7 +68,6 @@ router.post( res.setHeader('X-Accel-Buffering', 'no'); res.socket?.setNoDelay(true); res.flushHeaders(); - ssePadding(res); try { const converted = await convertPdfToStatementStreaming( diff --git a/frontend/nginx.conf b/frontend/nginx.conf index eaae9de..9d758cd 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -15,6 +15,7 @@ server { proxy_connect_timeout 5s; proxy_read_timeout 600s; proxy_buffering off; + gzip off; client_max_body_size 15m; }