SSE / Event Streaming wont work behind Cloudflare Proxy

Tools: NextJS 14, Coolify

I have an API event that does event streaming using ReadableStream. It works perfectly locally and when I access it directly without Cloudflare Proxy. But when it's hidden behind Cloudflare, it doesn't return a response or events. I already spent 6 hours solving this issue and can't seem to figure out anything right.

What I tried so far:
  • Bypass Caching using Cache Rule
  • Added Page Rule that bypass caching
  • Turn off Proxy via DNS
  • Override Response Headers to attach 'Transfer-Encoding': 'chunked', (Cloudflare seems to remove this IDK why) But this doesn't work either.
API Endpoint code:

const stream = new ReadableStream({
async start(controller) {
try {

await sendStreamMessage(controller, 'progress', {
...eventData
});



return new NextResponse(stream, {
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
'Transfer-Encoding': 'chunked',
},
});

If anyone from the Cloudflare team can guide me that would be great. :NotLikeThis:
image.png
Was this page helpful?