Files
bun.sh/test/js
Claude Bot 485017f93f fix: correct route registration order for WebSocket handlers
The key issue was understanding how uWebSockets handles WebSocket routes:

When app.ws() is called, it internally registers a GET handler that:
1. Checks for WebSocket upgrade headers (sec-websocket-key)
2. If present → handles WebSocket upgrade via the upgrade callback
3. If absent → calls req->setYield(true) to pass to next handler

This means app.ws() must be registered BEFORE app.method(.GET) for the
same path, so that:
- WebSocket requests → handled by app.ws()
- Regular GET requests → yield and fall through to GET handler

Changes:
- Register upgrade handler FIRST in user_routes_to_build (before method handlers)
- This ensures correct registration order in server.zig
- Removed websocket_only enum variant (not needed with correct ordering)
- Updated test to expect error on server creation (not connection time)
- Validate that route websocket requires upgrade handler

All 8 tests now passing:
✓ route-specific websocket handlers work independently
✓ route-specific websocket with data in upgrade
✓ route-specific websocket with close handler
✓ global websocket handler still works
✓ mix of route-specific and global websocket handlers
✓ route-specific websocket with multiple HTTP methods
✓ route-specific websocket without upgrade handler errors
✓ server.reload() preserves route-specific websocket handlers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 02:56:39 +00:00
..