diff --git a/frontend/src/lib/pocketbase.ts b/frontend/src/lib/pocketbase.ts index 1df3db1..89fc7a6 100644 --- a/frontend/src/lib/pocketbase.ts +++ b/frontend/src/lib/pocketbase.ts @@ -204,10 +204,19 @@ export const FALLBACK_FOOD: FoodItem[] = [ ]; const getPbUrl = () => { - if (typeof window !== 'undefined') { - return `${window.location.protocol}//${window.location.hostname}:8090`; + if (typeof import.meta !== 'undefined' && import.meta.env?.VITE_PB_URL) { + return import.meta.env.VITE_PB_URL; } - return 'http://127.0.0.1:8090'; + if (typeof window !== 'undefined') { + // In local development, PocketBase runs on dedicated port 8090 + if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') { + return `${window.location.protocol}//${window.location.hostname}:8090`; + } + // In production, Caddy reverse-proxies /api/* to PocketBase on port 443 (same origin) + return window.location.origin; + } + // Server-side (SSR) inside Docker container + return process.env.PB_URL || 'http://127.0.0.1:8090'; }; export const pb = new PocketBase(getPbUrl());