Fix web API URL for remote access (#550)

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.
This commit is contained in:
Vincent Schäffer
2026-04-25 10:59:58 -07:00
committed by GitHub
parent ed2eec591a
commit 627d40b42d
3 changed files with 48 additions and 5 deletions
+35 -1
View File
@@ -39,10 +39,44 @@ function invalidateAllServerData() {
queryClient.invalidateQueries();
}
export function getDefaultServerUrl(): string {
const fallback = 'http://127.0.0.1:17493';
if (!import.meta.env.PROD || typeof window === 'undefined') {
return fallback;
}
const { protocol, origin, hostname } = window.location;
if (
(protocol === 'http:' || protocol === 'https:') &&
origin &&
hostname !== 'tauri.localhost'
) {
return origin;
}
return fallback;
}
export function isLoopbackVoiceboxServerUrl(url: string): boolean {
try {
const parsed = new URL(url);
return (
parsed.port === '17493' &&
(parsed.hostname === '127.0.0.1' ||
parsed.hostname === 'localhost' ||
parsed.hostname === '[::1]' ||
parsed.hostname === '::1')
);
} catch {
return false;
}
}
export const useServerStore = create<ServerStore>()(
persist(
(set, get) => ({
serverUrl: 'http://127.0.0.1:17493',
serverUrl: getDefaultServerUrl(),
setServerUrl: (url) => {
const prev = get().serverUrl;
set({ serverUrl: url });