Files
temetro/frontend/lib/backend-url.ts
T
Khalid Abdi 403e0e38e9 frontend: runtime backend URL (LAN), voice dictation, version + update UI
Resolve the backend URL from the current host at runtime (lib/backend-url.ts)
so one build works on localhost and any clinic LAN IP without a rebuild; used
by the API client, auth client, and socket. Wire the AI-chat mic to the Web
Speech API with graceful fallback. Add a Settings "About & updates" panel
(current/latest version, update command, shareable network address) and an
optional dismissible update banner.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 21:34:30 +03:00

23 lines
1.1 KiB
TypeScript

// Resolves the backend's base URL at runtime instead of baking it in at build.
//
// temetro ships as a prebuilt image and is reached from many hosts — the
// server's own machine (localhost) and other departments over the LAN (the
// host's IP, e.g. http://192.168.1.20:3000). A URL baked at build time can't
// serve all of them, so in the browser we derive the backend URL from the page
// the user actually loaded (same hostname, the backend's port). Set
// NEXT_PUBLIC_API_URL to override for custom/reverse-proxied deployments.
const ENV_URL = process.env.NEXT_PUBLIC_API_URL?.trim();
// Backend port; override only if you publish the API on a non-default port.
const API_PORT = process.env.NEXT_PUBLIC_API_PORT?.trim() || "4000";
/** The backend origin to call from the current context. */
export function resolveBackendUrl(): string {
if (ENV_URL) return ENV_URL;
if (typeof window !== "undefined") {
return `${window.location.protocol}//${window.location.hostname}:${API_PORT}`;
}
// Server-side fallback (SSR/build); real browser calls use the branch above.
return "http://localhost:4000";
}