fix(dashboard): derive WebSocket URL from API base (no localhost fallback in prod)#106
Conversation
…ll back to localhost
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR refactors WebSocket URL resolution in dashboard/lib/api.ts: it removes the module-level WS_BASE constant, exports getWsBase() which prefers NEXT_PUBLIC_WS_URL or derives a ws(s)://.../ws URL from getServerBase(), and updates connectWebSocket to call getWsBase() for its URL while preserving existing connection and message-handling logic. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@dashboard/lib/api.ts`:
- Around line 52-57: The getWsBase function can produce a double-slash path when
NEXT_PUBLIC_API_URL or getServerBase() ends with "/api" or "/api/"; update
getWsBase to normalize the base by removing a trailing "/api" or "/api/" (use a
/\/api\/?$/ regex or equivalent trim) from the server/API base before replacing
the protocol and appending "/ws", and still short-circuit if NEXT_PUBLIC_WS_URL
is present; reference getWsBase, getServerBase, NEXT_PUBLIC_WS_URL and
NEXT_PUBLIC_API_URL when making the change.
🪄 Autofix (Beta)
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
Run ID: c2f4686c-dbeb-400d-988f-a0a51323f0c0
📒 Files selected for processing (1)
dashboard/lib/api.ts
42f50ca to
c845ced
Compare
Problem
In production the dashboard logs
WebSocket connection to 'ws://localhost:3000/ws' failed(repeatedly).WS_BASEread onlyNEXT_PUBLIC_WS_URL, which isn't set on the Vercel deployment, so it fell back to the localhost default — andNEXT_PUBLIC_*is inlined at build time, so it can't be fixed without also setting that var and a no-cache rebuild.Fix
Derive the WebSocket URL from the already-resolved server origin at runtime:
getWsBase()indashboard/lib/api.ts: returnsNEXT_PUBLIC_WS_URLif set, otherwisegetServerBase()withhttp(s)→ws(s)and a/wspath.connectWebSocket()now callsgetWsBase()instead of the build-timeWS_BASEconst (removed).Because
getServerBase()already resolves from the configuredNEXT_PUBLIC_API_URL(and the per-user localStoragetextrawl_serveroverride), prod now connects towss://<api-host>/wswith no extra env var and no build-cache footgun. Dev still resolves tows://localhost:3000/ws.Verify
biome check dashboard/lib/api.tsclean; dashboardtsc --noEmitclean.wss://…run.app/wsinstead of localhost.Cosmetic only (live-update socket); unrelated to the upload pipeline.