-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-base.ts
More file actions
25 lines (23 loc) · 1.04 KB
/
api-base.ts
File metadata and controls
25 lines (23 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Production backend (Cloud Run). Empty in dev → Vite proxy to localhost:8000.
* Set in Vercel: VITE_BACKEND_URL=https://prelude-backend-....run.app
*
* Echo on deployed is mitigated by routing agent playback through a WebRTC loopback
* so Chrome applies AEC to the mic (see src/lib/audio.ts). See PRD §12 Known Risks.
*/
const raw = (import.meta.env.VITE_BACKEND_URL as string | undefined) || "";
export const API_BASE = raw.replace(/\/$/, "");
export function apiUrl(path: string): string {
const p = path.startsWith("/") ? path : `/${path}`;
return API_BASE ? `${API_BASE}${p}` : p;
}
/** WebSocket origin for ADK session (same host as API_BASE, or current host in dev). */
export function wsSessionUrl(query: string): string {
if (API_BASE) {
const u = new URL(API_BASE);
const wsProto = u.protocol === "https:" ? "wss:" : "ws:";
return `${wsProto}//${u.host}/ws/session${query}`;
}
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
return `${protocol}//${window.location.host}/ws/session${query}`;
}