Compare commits
2 Commits
45a6f3d374
...
358fcaeff5
| Author | SHA1 | Date | |
|---|---|---|---|
| 358fcaeff5 | |||
|
|
67fed57118 |
@@ -28,17 +28,14 @@ function isJsonFile(file: { mimetype: string; originalname: string }): boolean {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sseWrite(res: import('express').Response, data: Record<string, unknown>) {
|
const SSE_PAD_TARGET = 4096;
|
||||||
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
function sseWrite(res: import('express').Response, data: Record<string, unknown>) {
|
||||||
* Send a 2 KB comment block to push past any proxy buffering threshold.
|
const payload = `data: ${JSON.stringify(data)}\n\n`;
|
||||||
* Nginx and other reverse proxies often buffer the first few KB before
|
const pad = Math.max(0, SSE_PAD_TARGET - payload.length);
|
||||||
* starting to stream — this padding forces the initial flush.
|
// SSE comment lines (": ...") are ignored by the browser but push
|
||||||
*/
|
// data past proxy buffer thresholds so each event is delivered immediately.
|
||||||
function ssePadding(res: import('express').Response) {
|
res.write(pad > 0 ? `: ${' '.repeat(pad)}\n${payload}` : payload);
|
||||||
res.write(`: ${' '.repeat(2048)}\n\n`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
@@ -71,7 +68,6 @@ router.post(
|
|||||||
res.setHeader('X-Accel-Buffering', 'no');
|
res.setHeader('X-Accel-Buffering', 'no');
|
||||||
res.socket?.setNoDelay(true);
|
res.socket?.setNoDelay(true);
|
||||||
res.flushHeaders();
|
res.flushHeaders();
|
||||||
ssePadding(res);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const converted = await convertPdfToStatementStreaming(
|
const converted = await convertPdfToStatementStreaming(
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ server {
|
|||||||
proxy_connect_timeout 5s;
|
proxy_connect_timeout 5s;
|
||||||
proxy_read_timeout 600s;
|
proxy_read_timeout 600s;
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
|
gzip off;
|
||||||
client_max_body_size 15m;
|
client_max_body_size 15m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user