Files
cli-e2e-mqoc92am/apps/kanban/src/lib/env.ts
2026-06-22 00:08:38 +02:00

18 lines
849 B
TypeScript

// Endpoints come from env, never hardcoded. Throws on a missing var rather than
// falling back to a localhost default, so a misconfigured deploy fails loudly.
//
// SSR (workerd inside the sandbox container) can't reach the external host port
// that VITE_API_URL points to. VITE_SERVER_API_URL holds the internal Caddy
// address (http://127.0.0.1:8080/api) and is set by generate-frontend-runtime.mjs
// for local sandbox mode. In deployed/hosted contexts VITE_SERVER_API_URL is
// unset and we fall back to VITE_API_URL, which is correct there.
export function apiUrl(): string {
const url = import.meta.env.SSR
? (import.meta.env.VITE_SERVER_API_URL ?? import.meta.env.VITE_API_URL)
: import.meta.env.VITE_API_URL
if (!url) {
throw new Error('VITE_API_URL is not set — point it at the Pikku API base URL')
}
return url
}