Update PocketBase URL handling and environment type definitions
This commit is contained in:
parent
bbb079f8fc
commit
7133409c04
2 changed files with 22 additions and 2 deletions
|
|
@ -1,10 +1,29 @@
|
|||
import PocketBase from 'pocketbase';
|
||||
|
||||
// Use env for PocketBase URL (falls back to local dev)
|
||||
const PB_URL = import.meta.env.VITE_PB_URL || 'pb.jeistk.apphub.co.za';
|
||||
// Derive PocketBase URL; add protocol if missing, default to https in production
|
||||
function buildPbUrl(raw?: string): string {
|
||||
let url = (raw || '').trim();
|
||||
if (!url) {
|
||||
return (import.meta.env.DEV ? 'http://127.0.0.1:8090' : 'https://pb.jeistk.apphub.co.za');
|
||||
}
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
// If looks like localhost or 127.* assume http, else https
|
||||
if (/^(localhost|127\.|10\.|192\.168\.)/i.test(url)) {
|
||||
url = 'http://' + url;
|
||||
} else {
|
||||
url = 'https://' + url;
|
||||
}
|
||||
}
|
||||
return url.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
const PB_URL = buildPbUrl(import.meta.env.VITE_PB_URL);
|
||||
const pb = new PocketBase(PB_URL);
|
||||
|
||||
// Optional: expose resolved URL for diagnostics
|
||||
// @ts-ignore
|
||||
pb.__resolvedUrl = PB_URL;
|
||||
|
||||
// Persist auth in localStorage (default behavior of SDK)
|
||||
// Do NOT auto-auth as admin here; let the app use user auth via AuthContext
|
||||
|
||||
|
|
|
|||
1
src/vite-env.d.ts
vendored
1
src/vite-env.d.ts
vendored
|
|
@ -7,6 +7,7 @@ interface ImportMetaEnv {
|
|||
readonly PROD: boolean
|
||||
readonly DEV: boolean
|
||||
readonly VITE_APP_TITLE?: string
|
||||
readonly VITE_PB_URL?: string
|
||||
// more env variables...
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue