Frontend dashboards previously found out about state changes only on their next poll tick (up to 15s, or 3s during a draw) — this adds a push channel so updates land as soon as they happen instead. - app/rounds/events.py: a small in-process pub/sub (RoundEventBroadcaster). The message carries no payload — it's just a "something changed, go refetch" signal, so it needs no auth and no knowledge of who's allowed to see what; personalization stays entirely in the existing REST endpoints. - GET /rounds/stream: an SSE endpoint exposing that channel, with keep-alive comments so it survives idle periods behind a reverse proxy, and a defensive MAX_SUBSCRIBERS cap (well above the ~100 concurrent users expected) — past it, the endpoint returns 503 instead of opening a stream, and callers just keep working off polling. - publish() calls added at every point that actually changes what a dashboard would want to know: new round opened, round status transitions (closing/drawing/paying_out/closed), a bet or withdrawal broadcast, any pending tx confirming (bet/withdrawal/payout), a deposit credited, and a new block tip arriving (the exact moment the "drawing" phase is waiting on). - Caddyfile: excludes /rounds/stream from gzip encoding, since compression would buffer output and defeat the point of a live stream. Single-process only by design for now (no cross-worker fan-out) and the notification is a generic broadcast rather than a per-user channel — both are deliberate scope decisions for the current ~100-user, single-container deployment, not oversights. Polling is left fully in place as a fallback; this is purely additive. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
18 lines
775 B
Caddyfile
18 lines
775 B
Caddyfile
# SITE_ADDRESS is the domain to serve (e.g. lottery.example.com) — Caddy
|
|
# automatically requests a Let's Encrypt certificate for it.
|
|
#
|
|
# Left at the default "localhost" (dev mode, no domain), Caddy detects it's
|
|
# not a public hostname and issues a locally-trusted self-signed certificate
|
|
# instead, via its internal CA. Browsers will still warn on first visit
|
|
# unless that CA is explicitly trusted — expected for local/dev use.
|
|
{$SITE_ADDRESS:localhost} {
|
|
# gzip buffers output, which would delay delivery on the SSE stream
|
|
# (/rounds/stream, app/api/routes/rounds.py) — it needs each event flushed
|
|
# to the client immediately, not batched. Everything else still compresses.
|
|
@not_sse {
|
|
not path /rounds/stream
|
|
}
|
|
encode @not_sse gzip
|
|
reverse_proxy app:8123
|
|
}
|