Fix SSE architecture for reliable connections #13

Merged
ryan merged 9 commits from fix/sse-architecture into main 2026-03-03 23:33:14 +00:00
Owner

Summary

Aligns the SSE/real-time architecture with portigo's working pattern to fix connection issues.

Changes

  • Reorder HandleGameEvents to create NATS subscriptions before SSE object
  • Use chi's middleware.NewWrapResponseWriter for proper http.Flusher support
  • Add slog-zerolog adapter for unified logging
  • Add ErrorLog to HTTP server for better error visibility
  • Change session Cookie.Secure to false for HTTP support
  • Change heartbeat from 15s to 10s
  • Remove ConnectionIndicator patching (was causing PatchElementsNoTargetsFound)

Root Cause

The logging middleware was wrapping the ResponseWriter without implementing http.Flusher, causing SSE data to be buffered instead of flushed immediately. This led to Cloudflare 524 timeouts.

## Summary Aligns the SSE/real-time architecture with portigo's working pattern to fix connection issues. ### Changes - Reorder `HandleGameEvents` to create NATS subscriptions before SSE object - Use chi's `middleware.NewWrapResponseWriter` for proper `http.Flusher` support - Add slog-zerolog adapter for unified logging - Add `ErrorLog` to HTTP server for better error visibility - Change session `Cookie.Secure` to false for HTTP support - Change heartbeat from 15s to 10s - Remove `ConnectionIndicator` patching (was causing `PatchElementsNoTargetsFound`) ### Root Cause The logging middleware was wrapping the ResponseWriter without implementing `http.Flusher`, causing SSE data to be buffered instead of flushed immediately. This led to Cloudflare 524 timeouts.
ryan added 1 commit 2026-03-03 22:17:08 +00:00
fix: align SSE architecture with portigo for reliable connections
All checks were successful
CI / Deploy / test (pull_request) Successful in 35s
CI / Deploy / lint (pull_request) Successful in 45s
CI / Deploy / deploy (pull_request) Has been skipped
b2b06a062b
- Reorder HandleGameEvents to create NATS subscriptions before SSE
- Use chi's middleware.NewWrapResponseWriter for proper http.Flusher support
- Add slog-zerolog adapter for unified logging
- Add ErrorLog to HTTP server for better error visibility
- Change session Cookie.Secure to false for HTTP support
- Change heartbeat from 15s to 10s
- Remove ConnectionIndicator patching (was causing PatchElementsNoTargetsFound)

The key fix was using chi's response writer wrapper which properly
implements http.Flusher, allowing SSE data to be flushed immediately
instead of being buffered.
ryan added 1 commit 2026-03-03 22:23:31 +00:00
refactor: extract GameService for Connect 4 NATS/chat handling
All checks were successful
CI / Deploy / test (pull_request) Successful in 16s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
8536f8e948
Move NATS subscription and chat room management into a dedicated
GameService, following the portigo service pattern. Handlers now
receive the service and call its methods instead of managing
NATS connections directly.
ryan added 1 commit 2026-03-03 22:25:30 +00:00
refactor: extract GameService for Snake NATS/chat handling
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 24s
CI / Deploy / deploy (pull_request) Has been skipped
de78ba6d39
Apply the same service pattern from Connect 4 to Snake game.
Handlers now receive the service and call its methods instead of
managing NATS connections directly. Also aligns heartbeat to 10s
and removes ConnectionIndicator patching (matching C4 changes).
ryan added 1 commit 2026-03-03 22:34:19 +00:00
feat: re-enable connection indicator for SSE status
All checks were successful
CI / Deploy / test (pull_request) Successful in 15s
CI / Deploy / lint (pull_request) Successful in 24s
CI / Deploy / deploy (pull_request) Has been skipped
cedcadfe3c
Add ConnectionIndicator to Connect 4 game page (Snake already had it).
Both games now patch the indicator on initial connect and every 10s
heartbeat, giving users visual feedback that SSE is connected.
ryan added 1 commit 2026-03-03 22:47:32 +00:00
fix: remove broken connection indicator
All checks were successful
CI / Deploy / test (pull_request) Successful in 15s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
1109dccdd8
The ConnectionIndicator component caused PatchElementsNoTargetsFound
errors due to complex nested IDs. Removing it for now - we can design
a better solution later if needed.
ryan added 1 commit 2026-03-03 22:52:44 +00:00
feat: replace connection indicator with live clock
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
155ac2c71a
A ticking clock serves as an implicit connection indicator - if it
stops updating, users know the connection is stale. Simpler and more
useful than a status dot.
ryan added 1 commit 2026-03-03 22:53:47 +00:00
feat: add status indicator dot to live clock
All checks were successful
CI / Deploy / test (pull_request) Successful in 13s
CI / Deploy / lint (pull_request) Successful in 26s
CI / Deploy / deploy (pull_request) Has been skipped
e0f5d555fb
ryan added 1 commit 2026-03-03 23:26:59 +00:00
feat: add hashfs for static asset cache busting and live clock
All checks were successful
CI / Deploy / test (pull_request) Successful in 32s
CI / Deploy / lint (pull_request) Successful in 42s
CI / Deploy / deploy (pull_request) Has been skipped
9a8fe4534d
- Add assets package with dev/prod build tags
- Dev: serve from filesystem with Cache-Control: no-store
- Prod: use hashfs for cache-busting URLs
- Add LiveClock component to show SSE connection status
- Update templates to use StaticPath for asset URLs
ryan added 1 commit 2026-03-03 23:29:04 +00:00
feat: tick live clock every second via SSE heartbeat
All checks were successful
CI / Deploy / test (pull_request) Successful in 14s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
c826981b4d
ryan merged commit 67a768ea22 into main 2026-03-03 23:33:14 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ryan/games#13