Skip to content

fix(dashboard): derive WebSocket URL from API base (no localhost fallback in prod)#106

Merged
jeffgreendesign merged 2 commits into
mainfrom
fix/dashboard-ws-url
Jun 10, 2026
Merged

fix(dashboard): derive WebSocket URL from API base (no localhost fallback in prod)#106
jeffgreendesign merged 2 commits into
mainfrom
fix/dashboard-ws-url

Conversation

@jeffgreendesign

Copy link
Copy Markdown
Owner

Problem

In production the dashboard logs WebSocket connection to 'ws://localhost:3000/ws' failed (repeatedly). WS_BASE read only NEXT_PUBLIC_WS_URL, which isn't set on the Vercel deployment, so it fell back to the localhost default — and NEXT_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:

  • New getWsBase() in dashboard/lib/api.ts: returns NEXT_PUBLIC_WS_URL if set, otherwise getServerBase() with http(s)ws(s) and a /ws path.
  • connectWebSocket() now calls getWsBase() instead of the build-time WS_BASE const (removed).

Because getServerBase() already resolves from the configured NEXT_PUBLIC_API_URL (and the per-user localStorage textrawl_server override), prod now connects to wss://<api-host>/ws with no extra env var and no build-cache footgun. Dev still resolves to ws://localhost:3000/ws.

Verify

  • biome check dashboard/lib/api.ts clean; dashboard tsc --noEmit clean.
  • After merge + the dashboard's prod redeploy, the console should connect to wss://…run.app/ws instead of localhost.

Cosmetic only (live-update socket); unrelated to the upload pipeline.

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Building Building Preview, Comment Jun 10, 2026 5:55pm
textrawl Ready Ready Preview, Comment Jun 10, 2026 5:55pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 840dc7c6-fd4f-4e61-860e-a95cfdd3b0d4

📥 Commits

Reviewing files that changed from the base of the PR and between 42f50ca and c845ced.

📒 Files selected for processing (1)
  • dashboard/lib/api.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • dashboard/lib/api.ts

Walkthrough

This 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing the WebSocket URL derivation to avoid localhost fallback in production.
Description check ✅ Passed The description provides a clear Problem-Fix structure, explains the rationale, and includes verification steps. However, it lacks explicit completion of the template's Type of Change and Checklist sections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dashboard-ws-url

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ded38f9 and 43d12fd.

📒 Files selected for processing (1)
  • dashboard/lib/api.ts

Comment thread dashboard/lib/api.ts
@jeffgreendesign jeffgreendesign merged commit 6cb5e50 into main Jun 10, 2026
7 of 8 checks passed
@jeffgreendesign jeffgreendesign deleted the fix/dashboard-ws-url branch June 10, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant