axiosleo/node-koapp/koapp-sse
Claude Code and agent skill by axiosleo/node-koapp
- community
Checking that the SKILL.md file is still in the repository.
Stream Server-Sent Events (SSE) from a @axiosleo/koapp Koa route using the KoaSSEMiddleware. Use when pushing real-time events to a browser over HTTP, implementing progress bars, live logs, notifications, or EventSource endpoints with text/event-stream, including ctx.koa.sse.send/close/keepAlive APIs.
Install
npx vskill@latest install axiosleo/node-koapp/koapp-sseSKILL.md
@axiosleo/koapp Server-Sent Events Middleware
Source: `src/middlewares/sse.js`.
KoaSSEMiddleware upgrades a Koa request to a Server-Sent Events (SSE) stream, setting the right headers and exposing ctx.sse.send(...) for pushing events to the browser over plain HTTP.
Use SSE when:
- You need server → client streaming (notifications, logs, live charts)
- You do NOT need client → server streaming (use koapp-apps WebSocket instead)
- You want a simple, proxy-friendly transport - SSE works over HTTP/1.1
Browsers reconnect automatically; most reverse proxies handle it fine.
Import
Middleware factory
The factory returns a standard Koa middleware (ctx, next) => {}.
Wiring into a router handler
Because the framework already dispatches routes via its workflow, invoke the middleware inside the handler, passing context.koa:
Key points:
- Call
await sse(context.koa, async () => {})- pass a no-opnext. - After that,
context.koa.sseexists. - Push events with
context.koa.sse.send(event); end with.close(). - Do not call
success / failed / resultin the same handler - SSE
takes over the response body.
Event shape
sse.send(data) accepts either a string or an object:
Raw wire output:
Lifecycle methods
| Method | When to use | |
|---|---|---|
ctx.sse.send(data) | Push one event | |
ctx.sse.keepAlive() | Send a :\n\n comment to keep the connection warm (called automatically every pingInterval ms for all active streams) | |
ctx.sse.close() | Emit a final { event: closeEvent } and end the stream |
The middleware maintains an internal ssePool and calls keepAlive on every registered stream every pingInterval ms. Manual calls are rarely needed.
Reacting to client disconnect
The middleware listens to close / error events on the SSE stream and calls an internal close() that:
- Removes the stream from the pool
unpipe()+destroy()the stream- Ends the Koa response
- Destroys the underlying socket
You can listen yourself too:
Long-lived handlers
The handler function must remain alive while the SSE stream is open. Don't return from it immediately; either keep pushing inline, or spawn a background task and let it own the lifecycle:
The framework's workflow will see the handler resolve, but the response body (the SSE stream) remains open until you close() it or the client disconnects.
Browser client
Browsers automatically reconnect on network blips.
Pairing with other koapp pieces
- Validate the upgrade with a router-level validator on
query
(e.g. auth token) - koapp-router
- Authenticate via session cookie - the middleware does not touch auth
- Control backpressure by only pushing when
context.koa.sse.writable
Common pitfalls
- Calling
success / failed / result / context.koa.body = ...in the
same handler conflicts with the SSE stream and yields incomplete output.
- Using HTTP/2 requires enabling SSE on the server side - the default
Node HTTP/1.1 works out of the box.
- Firewall / proxy buffering can delay events. Set
X-Accel-Buffering: no for nginx: ``javascript context.koa.set('X-Accel-Buffering', 'no'); ` Do this **before** calling sse(context.koa, ...)`.
- The middleware's global
setIntervalheartbeat keeps all open SSE
connections warm; it does not leak across requests because each stream auto-removes itself from the pool on close.
See also
- Real-time browser apps needing bi-directional traffic → koapp-apps (WebSocket)
- Progress indicators for long-running HTTP jobs → this skill +
Workflowfrom@axiosleo/cli-tool - Concrete SSE recipes: examples.md
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingassets/skills/koapp-sse/SKILL.md
Popularity
- Repository stars
- 44
- Repository forks
- 11
- 7-day trend score
- 19
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/axiosleo/node-koapp/koapp-sse)