refactor: move PocketBase client to services and use the reachable URL

This commit is contained in:
rajun 2026-10-27 16:28:51 +05:30
parent 82b0db671c
commit 04751ff97e
2 changed files with 12 additions and 7 deletions

View File

@ -1,7 +0,0 @@
import PocketBase from 'pocketbase';
const rawUrl = import.meta.env.VITE_POCKETBASE_URL ?? '';
// 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);

View File

@ -0,0 +1,12 @@
import PocketBase from 'pocketbase';
import { reachableUrl } from '~/lib/local-url';
// Defaults to the local PocketBase dev server when VITE_POCKETBASE_URL is unset
const rawUrl = (import.meta.env.VITE_POCKETBASE_URL ?? '').trim() || '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);