fix(client): use window.location.hostname for remote/Docker deployments - #123
Conversation
When running in Docker and accessing OmniVoice from a remote machine, the frontend was hardcoded to call 127.0.0.1 for all API requests, causing every endpoint to fail with ERR_CONNECTION_REFUSED. Fix: detect Tauri context via window.__TAURI__ and use 127.0.0.1 only for native desktop builds. In browser/Docker deployments, fall back to window.location.hostname so remote access works correctly. Fixes debpalash#120
📝 WalkthroughWalkthroughThe API endpoint construction in the frontend client is updated to dynamically select the backend host based on the deployment context. Tauri builds continue using localhost, while browser-based deployments now use the current window hostname to reach remote backends. ChangesAPI Host Selection
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 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 unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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: 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 `@frontend/src/api/client.ts`:
- Around line 7-11: The API base resolution in frontend/src/api/client.ts is out
of sync with the contract in frontend/src/utils/apiBase.ts: update the Tauri
detection to check window.__TAURI_INTERNALS__ || window.__TAURI__ (not just
window.__TAURI__), derive the protocol from window.location.protocol when not
running under Tauri (avoid hardcoded "http://"), and use the same environment
override variable name VITE_OMNIVOICE_API instead of viteEnv.VITE_API_URL;
update the logic that builds API (variables _host, _port, API and the viteEnv
usage) so the final API string matches the protocol+host:port format used by
apiBase.ts and allows the env override to take precedence.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ffe1123e-6814-4ed8-8e01-0c026cb0120f
📒 Files selected for processing (1)
frontend/src/api/client.ts
| const _host = | ||
| typeof window !== 'undefined' && window.__TAURI__ | ||
| ? '127.0.0.1' | ||
| : (typeof window !== 'undefined' ? window.location.hostname : '127.0.0.1'); | ||
| export const API = viteEnv.VITE_API_URL || `http://${_host}:${_port}`; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify current runtime-contract usage consistency (read-only).
rg -n -C3 '__TAURI_INTERNALS__|__TAURI__|getApiBase\(|window\.location\.protocol|window\.location\.hostname' frontendRepository: debpalash/OmniVoice-Studio
Length of output: 15050
Major: align frontend/src/api/client.ts API base resolution with frontend/src/utils/apiBase.ts contract (Tauri + protocol + env override)
- Tauri detection drift:
client.tstreats Tauri aswindow.__TAURI__only, whileapiBase.tsuseswindow.__TAURI_INTERNALS__ || window.__TAURI__. - Protocol drift / mixed-content risk:
client.tshardcodeshttp://..., butapiBase.tsresolves the protocol fromwindow.location.protocol(tests coverhttps). - Env override key mismatch:
client.tsusesviteEnv.VITE_API_URL, whileapiBase.tsoverrides viaVITE_OMNIVOICE_API(override behavior can diverge between call sites).
🤖 Prompt for 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.
In `@frontend/src/api/client.ts` around lines 7 - 11, The API base resolution in
frontend/src/api/client.ts is out of sync with the contract in
frontend/src/utils/apiBase.ts: update the Tauri detection to check
window.__TAURI_INTERNALS__ || window.__TAURI__ (not just window.__TAURI__),
derive the protocol from window.location.protocol when not running under Tauri
(avoid hardcoded "http://"), and use the same environment override variable name
VITE_OMNIVOICE_API instead of viteEnv.VITE_API_URL; update the logic that builds
API (variables _host, _port, API and the viteEnv usage) so the final API string
matches the protocol+host:port format used by apiBase.ts and allows the env
override to take precedence.
Et-008
left a comment
There was a problem hiding this comment.
The _host variable condition can be written a bit cleaner...
const _host = typeof window !== 'undefined' && !window.__TAURI__ ? window.location.hostname : '127.0.0.1';
Problem
When running OmniVoice Studio in Docker and accessing it from a remote machine (e.g. over Tailscale or LAN), the frontend fails entirely — every API call hits
ERR_CONNECTION_REFUSEDbecause the client is hardcoded to127.0.0.1.This is tracked in #120.
Root Cause
frontend/src/api/client.tsalways builds the API base URL as:`http://127.0.0.1:${_port}`This works fine in Tauri desktop builds (where the backend sidecar runs locally), but breaks in any browser-based deployment where the server is on a different host.
Fix
Detect the Tauri context via
window.__TAURI__and use127.0.0.1only for native desktop builds. For all other cases (Docker, web server), usewindow.location.hostnameso the frontend talks to whatever host it was loaded from.127.0.0.1)VITE_API_URLenv override still takes priorityFixes #120
Summary by CodeRabbit