avoid buffering when reverse-proxied through nginx

Massimo Melina committed Dec 24, 2021 at 18:00 UTC 2f58c75150c91c4acdcdbadfa0510011eb13d611
1 file changed +4 -3
src/sse.ts
+4 -3
@@ -7,9 +7,10 @@ export default function createSSE(ctx: Koa.Context) {
7 socket.setNoDelay(true)
8 socket.setKeepAlive(true)
9 ctx.set({
10 - "Content-Type": "text/event-stream",
11 - "Cache-Control": "no-cache",
12 - "Connection": "keep-alive",
10 + 'Content-Type': 'text/event-stream',
11 + 'Cache-Control': 'no-cache',
12 + 'Connection': 'keep-alive',
13 + 'X-Accel-Buffering': 'no', // avoid buffering when reverse-proxied through nginx
14 })
15 ctx.status = 200
16 const stream = ctx.body = new PassThrough()