fix: eliminate SSE buffering through Nginx proxy #8
@@ -32,6 +32,15 @@ function sseWrite(res: import('express').Response, data: Record<string, unknown>
|
|||||||
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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`);
|
||||||
|
}
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
@@ -60,7 +69,9 @@ router.post(
|
|||||||
res.setHeader('Cache-Control', 'no-cache');
|
res.setHeader('Cache-Control', 'no-cache');
|
||||||
res.setHeader('Connection', 'keep-alive');
|
res.setHeader('Connection', 'keep-alive');
|
||||||
res.setHeader('X-Accel-Buffering', 'no');
|
res.setHeader('X-Accel-Buffering', 'no');
|
||||||
|
res.socket?.setNoDelay(true);
|
||||||
res.flushHeaders();
|
res.flushHeaders();
|
||||||
|
ssePadding(res);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const converted = await convertPdfToStatementStreaming(
|
const converted = await convertPdfToStatementStreaming(
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ server {
|
|||||||
proxy_connect_timeout 5s;
|
proxy_connect_timeout 5s;
|
||||||
proxy_read_timeout 600s;
|
proxy_read_timeout 600s;
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
chunked_transfer_encoding off;
|
|
||||||
client_max_body_size 15m;
|
client_max_body_size 15m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user