From 04751ff97e07577ac7663ae2a0e0a0bb8d18d444 Mon Sep 17 00:00:00 2001 From: rajun Date: Tue, 27 Oct 2026 16:28:51 +0530 Subject: [PATCH] refactor: move PocketBase client to services and use the reachable URL --- app/lib/pocketbase.ts | 7 ------- app/services/pocketbase.ts | 12 ++++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) delete mode 100644 app/lib/pocketbase.ts create mode 100644 app/services/pocketbase.ts diff --git a/app/lib/pocketbase.ts b/app/lib/pocketbase.ts deleted file mode 100644 index de15a2c..0000000 --- a/app/lib/pocketbase.ts +++ /dev/null @@ -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); diff --git a/app/services/pocketbase.ts b/app/services/pocketbase.ts new file mode 100644 index 0000000..4bfdac2 --- /dev/null +++ b/app/services/pocketbase.ts @@ -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);