feat(api): websocket gateway - #297
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe PR adds short-lived WebSocket JWT tickets, an authenticated ticket endpoint, WebSocket channel subscriptions, heartbeat handling, and invalidation broadcasts. AMA question and tag routes publish invalidations through guild- and AMA-specific channels. ChangesRealtime WebSocket support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant WebSocketServer
participant WsHub
participant AMA route
Client->>API: GET /v3/ws/ticket
API-->>Client: WebSocket ticket
Client->>WebSocketServer: Connect to /v3/ws with ticket
WebSocketServer->>WsHub: Register channel subscription
Client->>AMA route: Modify AMA question
AMA route->>WsHub: Broadcast invalidate message
WsHub-->>Client: Send channel invalidation
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@services/api/src/core/server.ts`:
- Around line 123-127: Move the realtimeChannel broadcast in the request
handling flow to execute only after response handling completes, and guard it
with a 2xx res.statusCode check. Preserve the existing channel resolution and
wsHub.broadcast behavior for successful responses, while preventing
invalidations when handlers return 4xx or 5xx statuses.
In `@services/api/src/routes/ws/getTicket.ts`:
- Around line 23-30: Update the getTicket handler to set the response
Cache-Control header to no-store before returning the ticket, ensuring the
bearer credential is not cached while preserving the existing ticket creation
and response behavior.
In `@services/api/src/ws/server.ts`:
- Around line 114-119: Stop passing ticket data through the WebSocket connection
event, whose listener should receive only the WebSocket and request. Introduce a
local setup function that accepts the upgraded WebSocket, request, and ticket,
move the ticket-dependent connection setup from the `wss.on('connection')`
listener into it, and invoke it directly from the `handleUpgrade` callback
instead of emitting a third argument.
- Around line 94-98: Update the upgrade handler around the
httpServer.on('upgrade') callback to destroy the socket whenever url.pathname is
not WS_PATH, ensuring unsupported paths are closed rather than left open. Add an
explicit dispatcher for any other upgrade protocol while preserving the existing
/v3/ws handling.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4c603402-3eab-4bc4-b4bc-e665c18928dc
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (17)
packages/private/backend-core/src/index.tspackages/private/backend-core/src/lib/wsTicket.tspackages/private/core/src/index.tspackages/private/core/src/lib/realtimeChannels.tsservices/api/package.jsonservices/api/src/app.tsservices/api/src/core/__tests__/server.test.tsservices/api/src/core/route.tsservices/api/src/core/server.tsservices/api/src/routes/ama/questions/mergeQuestion.tsservices/api/src/routes/ama/questions/mergeQuestionsBulk.tsservices/api/src/routes/ama/questions/sendQuestion.tsservices/api/src/routes/ama/questions/updateQuestion.tsservices/api/src/routes/ama/tags/createTag.tsservices/api/src/routes/ws/getTicket.tsservices/api/src/ws/hub.tsservices/api/src/ws/server.ts
No description provided.