Skip to content

Fix web API URL for remote access#550

Open
vi-sch wants to merge 1 commit intojamiepine:mainfrom
vi-sch:fix/web-remote-api-url
Open

Fix web API URL for remote access#550
vi-sch wants to merge 1 commit intojamiepine:mainfrom
vi-sch:fix/web-remote-api-url

Conversation

@vi-sch
Copy link
Copy Markdown

@vi-sch vi-sch commented Apr 24, 2026

Default production web builds to the page origin so remote Docker and LAN users do not fetch from browser-local localhost. Preserve the local/Tauri fallback and repair stale persisted loopback URLs.

Summary by CodeRabbit

  • New Features

    • Server URL configuration now dynamically determines defaults based on the runtime environment, replacing hardcoded values for better cross-deployment compatibility
    • Added validation utility for more reliable local server detection
  • Bug Fixes

    • Improved server settings reconciliation during startup to properly synchronize user-persisted preferences with computed defaults

Default production web builds to the page origin so Docker and LAN users do not fetch from browser-local localhost. Preserve the local/Tauri fallback and repair stale persisted loopback URLs.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

📝 Walkthrough

Walkthrough

The pull request introduces dynamic server URL initialization by replacing hardcoded defaults with computed values via a new getDefaultServerUrl() function. On non-Tauri platforms, the app startup now reconciles the persisted server URL with the computed default, overwriting it when necessary. Two new helper functions validate and compute server URLs across the codebase.

Changes

Cohort / File(s) Summary
Server URL Initialization
app/src/stores/serverStore.ts, web/src/platform/lifecycle.ts
Introduced getDefaultServerUrl() and isLoopbackVoiceboxServerUrl() helper functions; replaced hardcoded loopback URL (http://localhost:17493) with dynamic computation from getDefaultServerUrl(); default store value now uses computed URL instead of constant.
App Startup Logic
app/src/App.tsx
Added reconciliation logic that fetches persisted serverUrl, computes the default, and overwrites the store value when the current URL is a loopback Voicebox URL differing from the computed default.

Sequence Diagram(s)

sequenceDiagram
    participant App as App.tsx
    participant Store as ServerStore
    participant Helper as getDefaultServerUrl()
    participant Validator as isLoopbackVoiceboxServerUrl()
    
    App->>Store: Fetch persisted serverUrl
    activate Store
    Store-->>App: Return stored serverUrl
    deactivate Store
    
    App->>Helper: Compute default server URL
    activate Helper
    Helper-->>App: Return computed default
    deactivate Helper
    
    App->>Validator: Check if current URL is loopback Voicebox
    activate Validator
    Validator-->>App: Return validation result
    deactivate Validator
    
    alt Current differs from default
        App->>Store: Overwrite serverUrl with computed default
        activate Store
        Store-->>App: Confirm update
        deactivate Store
    end
    
    App-->>App: Server initialization complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Server URLs now dance to a computed tune,
No hardcoded paths beneath the moon!
Default values spring forth with grace,
Loopback helpers find their place,
The startup reconciles with flair—thump thump 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix web API URL for remote access' clearly captures the main objective of the pull request, which is to resolve web API URL issues for remote clients accessing the service, as evidenced by the changes to server URL resolution logic across multiple files.
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 unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
app/src/stores/serverStore.ts (1)

61-74: Remove the unreachable '[::1]' branch instead.

Per the WHATWG URL spec, URL.hostname returns IPv6 addresses without brackets — for example, parsing http://[::1]:17493/ results in hostname === '::1', not '[::1]'. The bare '::1' case correctly handles IPv6 loopback; the '[::1]' check is dead code and should be removed for clarity.

♻️ Optional cleanup
     return (
       parsed.port === '17493' &&
       (parsed.hostname === '127.0.0.1' ||
         parsed.hostname === 'localhost' ||
-        parsed.hostname === '[::1]' ||
         parsed.hostname === '::1')
     );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/stores/serverStore.ts` around lines 61 - 74, The
isLoopbackVoiceboxServerUrl function contains an unreachable branch checking for
the hostname '[::1]'; remove that check so the hostname comparisons only include
'127.0.0.1', 'localhost', and '::1'. Update the return condition in
isLoopbackVoiceboxServerUrl to drop the '[::1]' case and keep the try/catch and
URL parsing logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@app/src/stores/serverStore.ts`:
- Around line 61-74: The isLoopbackVoiceboxServerUrl function contains an
unreachable branch checking for the hostname '[::1]'; remove that check so the
hostname comparisons only include '127.0.0.1', 'localhost', and '::1'. Update
the return condition in isLoopbackVoiceboxServerUrl to drop the '[::1]' case and
keep the try/catch and URL parsing logic unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05b7c3fd-f410-48ff-95e1-500e79f6b113

📥 Commits

Reviewing files that changed from the base of the PR and between ed2eec5 and 33c7fe9.

📒 Files selected for processing (3)
  • app/src/App.tsx
  • app/src/stores/serverStore.ts
  • web/src/platform/lifecycle.ts

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