Fix WebSocket connection failure due to incorrect sub-routing setup #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
WebSocket connections were failing with
400 Bad Requesterrors when usingwebsocator other WebSocket clients:❯ websocat ws://127.0.0.1:3000/ws?hash=c39ecb75e8b3f5aac139d775e215bb0a websocat: WebSocketError: WebSocketError: Received unexpected status code (400 Bad Request) websocat: error runningRoot Cause
The WebSocket implementation was using
@hono/node-wswith sub-routing (app.route("/ws", wsRoute)), which prevented the WebSocket upgrade process from working correctly. The WebSocket setup was isolated in a separate route module that couldn't properly inject WebSocket support into the main server.Solution
Moved the WebSocket configuration from sub-routes to the main application:
server/routes/ws.tsusingcreateNodeWebSocket({ app })on a sub-appserver/main.tsusingcreateNodeWebSocket({ app })on the main appvalidateHash) and WebSocket handlersTechnical Details
The key changes:
createNodeWebSocket({ app })now operates on the primary Hono instancevalidateHashmiddleware works correctly with WebSocket upgradeVerification
✅ WebSocket connections now work correctly:
✅ Hash validation works:
✅ Backward compatibility maintained:
Impact
This fixes the fundamental WebSocket connectivity issue. Users can now successfully connect to WebSocket endpoints using
websocat, browser WebSocket APIs, or other WebSocket clients when providing valid problem hashes.Created from VS Code via the GitHub Pull Request extension.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.