import PocketBase from 'pocketbase'; // VITE_ vars are inlined at BUILD time, not runtime. If the image is built // without --build-arg VITE_POCKETBASE_URL, this is empty and the SDK silently // resolves requests against `https://` — producing `https://api/collections/...` // which fails as a DNS error that looks like CORS. Fail loudly instead. const rawUrl = import.meta.env.VITE_POCKETBASE_URL; if (!rawUrl) { throw new Error( 'VITE_POCKETBASE_URL is not set. It must be passed as a --build-arg when ' + 'building the Docker image — setting it at runtime has no effect, because ' + 'Vite inlines VITE_ variables into the bundle at build time.', ); } // Ensure URL always has a protocol so PocketBase SDK treats it as absolute const pbUrl = rawUrl.startsWith('http') ? rawUrl : `https://${rawUrl}`; export const pb = new PocketBase(pbUrl);