forked from rajun/ar-test
20 lines
953 B
TypeScript
20 lines
953 B
TypeScript
import PocketBase from 'pocketbase';
|
|
import { reachableUrl } from '~/lib/local-url';
|
|
|
|
const envUrl = (import.meta.env.VITE_POCKETBASE_URL ?? '').trim();
|
|
|
|
// VITE_ vars are inlined at build time, so a production image built without --build-arg VITE_POCKETBASE_URL must fail loudly
|
|
if (!envUrl && import.meta.env.PROD) {
|
|
throw new Error('VITE_POCKETBASE_URL is not set. Pass it as a --build-arg when building the Docker image; setting it at runtime has no effect.');
|
|
}
|
|
|
|
// Defaults to the local PocketBase dev server when VITE_POCKETBASE_URL is unset
|
|
const rawUrl = envUrl || 'http://127.0.0.1:8099';
|
|
// 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(reachableUrl(pbUrl));
|
|
|
|
// Loaders fire several requests to the same collection in parallel; the SDK would otherwise cancel all but the last
|
|
pb.autoCancellation(false);
|