diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index e590f984b..4ed01d0b6 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -1,4 +1,4 @@ -import { VARS } from '$lib/system'; +import { isMultiRegionSupported, VARS } from '$lib/system'; import { Account, Assistant, @@ -42,7 +42,7 @@ export function getApiEndpoint(region?: string): string { const hostname = url.hostname; // If instance supports multi-region, add the region subdomain. - const subdomain = VARS.APPWRITE_MULTI_REGION ? getSubdomain(region) : ''; + const subdomain = isMultiRegionSupported() ? getSubdomain(region) : ''; return `${protocol}//${subdomain}${hostname}/v1`; } diff --git a/src/lib/system.ts b/src/lib/system.ts index 80f7c3a8d..e39b7504c 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -10,8 +10,7 @@ export const VARS = { CONSOLE_MODE: (env.PUBLIC_CONSOLE_MODE as Mode) ?? undefined, APPWRITE_ENDPOINT: env.PUBLIC_APPWRITE_ENDPOINT ?? undefined, GROWTH_ENDPOINT: env.PUBLIC_GROWTH_ENDPOINT ?? undefined, - PUBLIC_STRIPE_KEY: env.PUBLIC_STRIPE_KEY ?? undefined, - APPWRITE_MULTI_REGION: env.PUBLIC_APPWRITE_MULTI_REGION === 'true' + PUBLIC_STRIPE_KEY: env.PUBLIC_STRIPE_KEY ?? undefined }; export const ENV = { @@ -28,3 +27,16 @@ export const isDev = ENV.DEV; export const isProd = ENV.PROD; export const hasStripePublicKey = !!VARS.PUBLIC_STRIPE_KEY; export const GRACE_PERIOD_OVERRIDE = false; + +/** + * Returns true if multi-region is supported. + */ +export function isMultiRegionSupported(): boolean { + if (env.PUBLIC_APPWRITE_MULTI_REGION === 'true') return true; + + try { + return new URL(VARS.APPWRITE_ENDPOINT).hostname.endsWith('cloud.appwrite.io'); + } catch { + return false; + } +}