Refactor PocketBase client initialization, update HTML template for favicon handling, and remove redundant text in main components for improved clarity and performance in SvelteKit project.
This commit is contained in:
+21
-1
@@ -2,4 +2,24 @@ import PocketBase from "pocketbase";
|
||||
|
||||
const POCKETBASE_URL = "https://pocketbase.ccllc.pro";
|
||||
|
||||
export const pb = new PocketBase(POCKETBASE_URL);
|
||||
/** Base URL for API/file URLs; safe to use during SSR. */
|
||||
export const POCKETBASE_BASE_URL = POCKETBASE_URL;
|
||||
|
||||
let _pb: PocketBase | null = null;
|
||||
|
||||
/** PocketBase client — only created in the browser to avoid fetch during SSR. */
|
||||
export function getPb(): PocketBase {
|
||||
if (typeof window === "undefined") {
|
||||
throw new Error("PocketBase client is only available in the browser. Use load/actions for server data.");
|
||||
}
|
||||
if (!_pb) _pb = new PocketBase(POCKETBASE_URL);
|
||||
return _pb;
|
||||
}
|
||||
|
||||
/** Lazy client proxy: baseUrl is safe during SSR; other access creates the client in the browser only. */
|
||||
export const pb = new Proxy({} as PocketBase, {
|
||||
get(_, prop) {
|
||||
if (prop === "baseUrl") return POCKETBASE_BASE_URL;
|
||||
return (getPb() as Record<string, unknown>)[prop as string];
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user