better-sse

Implements tenant-scoped Server-Sent Events broadcasting with better-sse across Express workers and Next.js clients.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/gengirish/dropflow --skill better-sse-gengirish
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: better-sse
Source: https://github.com/gengirish/dropflow/tree/main/.cursor/skills/better-sse
Command: npx skills add https://github.com/gengirish/dropflow --skill better-sse-gengirish

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-sse.

What problem does it solve? Building real-time updates for multi-tenant applications requires wiring together an SSE broadcaster, authenticated proxy routes, and client-side event handling without leaking events across tenants. This Skill provides the complete pattern for live order, workflow, inventory, and shipment updates in DropFlow. ## Core Features & Use Cases - Tenant-Scoped SSE Broadcaster: Creates one better-sse channel per tenantId, registers sessions, and cleans up empty channels to prevent cross-tenant event leakage. - Authenticated Proxy Route: Proxies SSE streams through a Next.js route at /api/v1/sse that adds Clerk auth and forwards the worker secret. - Typed Client Hook: Provides a useSSE React hook that subscribes to typed events (WORKFLOW_STEP, ORDER_STATUS, INVENTORY_ALERT, SHIPMENT_UPDATE) for cache invalidation. - Use Case: When a DAG workflow step completes in the worker, broadcast a WORKFLOW_STEP event so the web dashboard updates the order status in real time via TanStack Query invalidation. ## Quick Start Use the better-sse skill to implement the tenant-scoped SSE broadcaster and useSSE hook for live workflow updates.

Frequently Asked Questions about better-sse

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement Server-Sent Events with better-sse in Express?▼

Create a session with createSession(req, res), register it on a channel from createChannel(), and call channel.broadcast(event, eventType) to push events. Deregister sessions on request close to avoid leaks.

How to proxy SSE through a Next.js API route with authentication?▼

Fetch the worker SSE endpoint with the worker secret header, then return a new Response wrapping upstream.body with Content-Type text/event-stream, Cache-Control no-cache, and Connection keep-alive headers.

How do I prevent cross-tenant event leakage in SSE?▼

Maintain one channel per tenantId in a Map and only broadcast to the channel matching that tenant. Delete the channel when its session count reaches zero to free resources.

Does EventSource support custom event types in React?▼

Yes, EventSource supports named events via source.addEventListener for each type such as WORKFLOW_STEP or ORDER_STATUS, plus a generic message listener. The useSSE hook registers all typed listeners and closes the source on unmount.

Why is my SSE connection not receiving events from the worker?▼

Check that the x-worker-secret header matches WORKER_SECRET, since mismatches return 401. Also verify the client subscribes to the same event type names the broadcaster emits.