52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
/**
|
|
* PocketBase Client Configuration
|
|
*
|
|
* Singleton PocketBase client instance with automatic environment detection.
|
|
* Connects to local instance in development, production URL in production.
|
|
*/
|
|
|
|
import PocketBase from "pocketbase";
|
|
|
|
/**
|
|
* PocketBase URL configuration based on environment
|
|
* Development: Local PocketBase instance (http://127.0.0.1:8090)
|
|
* Production: Production PocketBase instance
|
|
*
|
|
* @returns PocketBase API base URL
|
|
*/
|
|
const getPocketBaseUrl = (): string => {
|
|
const isDev = import.meta.env.MODE === "development";
|
|
|
|
if (isDev) {
|
|
return "http://localhost:8090";
|
|
}
|
|
|
|
/* Production URL - configure via build process or use relative URL */
|
|
return import.meta.env.VITE_POCKETBASE_URL || "http://localhost:8090";
|
|
};
|
|
|
|
/**
|
|
* Singleton PocketBase client instance
|
|
* Import this instance throughout the application for all PocketBase operations
|
|
*/
|
|
export const pb = new PocketBase(getPocketBaseUrl());
|
|
|
|
/**
|
|
* Disable auto-cancellation to prevent request interruptions
|
|
* By default, PocketBase cancels pending requests when new ones are made,
|
|
* which can cause issues with concurrent requests and real-time subscriptions
|
|
*/
|
|
pb.autoCancellation(false);
|
|
|
|
/**
|
|
* PocketBase collection names
|
|
* Centralized collection name constants to avoid typos and enable refactoring
|
|
*/
|
|
export const Collections = {
|
|
About: "about",
|
|
Companies: "companies",
|
|
Notices: "notices",
|
|
FloorPlans: "floor_plans",
|
|
Rooms: "rooms",
|
|
} as const;
|