Menu

Streaming Koa server-sent events on Bun: the four things that broke, and what Flight 3.0.1 changed
📰

Streaming Koa server-sent events on Bun: the four things that broke, and what Flight 3.0.1 changed

DEV Community: koa·Dan Stephenson·9 days ago
#irBDtP5R
#devtokoa#devto#dev#stream#response
Long article (1013 words) — no AI summary yet.
Reading 0:00
15s threshold

Bytewells by ThoughtPivot

Flight is ThoughtPivot's open-source web framework. Since 3.0.0 it ships flight-bun , a server that runs on Bun.serve and mounts existing Koa backends ( export default router.routes() ) through a Koa-compat layer. On Oct 18 we pushed 3.0.1 to main. It fixes one thing that matters a lot if you stream: Koa server-sent events (SSE) on flight-bun were buffered until res.end() . The client connected, the server wrote events, and nothing arrived until the stream closed.

The fix touched four separate parts of the stack. Each one was a reasonable choice for request-response traffic and a bug for a stream. This post walks through them, because the same four assumptions are probably sitting in your middleware too.

Commit: https://github.com/thoughtpivot/flight/commit/7db959993b20593e192fbeb599d164751c8ecaf1

The route we wanted to work

This is the usual way to stream from Koa. Nothing Bun-specific:

router . get ( ' /events ' , ( ctx ) => { ctx .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.