From 295463aa371e60b77dd055fa8e2e4da34eeba5cb Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 16 May 2025 14:16:16 +0000 Subject: [PATCH 1/3] fix: multi region support for cached env files --- src/lib/system.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/system.ts b/src/lib/system.ts index e39b7504c..7187df329 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -1,5 +1,6 @@ import { env } from '$env/dynamic/public'; import { dev } from '$app/environment'; +import { getApiEndpoint } from '$lib/stores/sdk'; export const enum Mode { CLOUD = 'cloud', @@ -35,7 +36,8 @@ 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'); + const endpoint = getApiEndpoint(); + return new URL(endpoint).hostname.endsWith('cloud.appwrite.io'); } catch { return false; } From 99b20f41261888c547c106c0bb21754dac048f7c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 16 May 2025 16:18:47 +0200 Subject: [PATCH 2/3] Simplify URL extraction in isMultiRegionSupported function --- src/lib/system.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/system.ts b/src/lib/system.ts index 7187df329..5c78c491f 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -36,8 +36,7 @@ export function isMultiRegionSupported(): boolean { if (env.PUBLIC_APPWRITE_MULTI_REGION === 'true') return true; try { - const endpoint = getApiEndpoint(); - return new URL(endpoint).hostname.endsWith('cloud.appwrite.io'); + return new URL(getApiEndpoint()).hostname.endsWith('cloud.appwrite.io'); } catch { return false; } From 030618196a08ea46376797d026c6f21dc8114e53 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 16 May 2025 16:31:39 +0200 Subject: [PATCH 3/3] Fix isMultiRegionSupported to accept URL parameter --- src/lib/stores/sdk.ts | 2 +- src/lib/system.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 4ed01d0b6..bf463d972 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -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 = isMultiRegionSupported() ? getSubdomain(region) : ''; + const subdomain = isMultiRegionSupported(url) ? getSubdomain(region) : ''; return `${protocol}//${subdomain}${hostname}/v1`; } diff --git a/src/lib/system.ts b/src/lib/system.ts index 5c78c491f..a23558304 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -1,6 +1,5 @@ import { env } from '$env/dynamic/public'; import { dev } from '$app/environment'; -import { getApiEndpoint } from '$lib/stores/sdk'; export const enum Mode { CLOUD = 'cloud', @@ -32,11 +31,11 @@ export const GRACE_PERIOD_OVERRIDE = false; /** * Returns true if multi-region is supported. */ -export function isMultiRegionSupported(): boolean { +export function isMultiRegionSupported(url: URL): boolean { if (env.PUBLIC_APPWRITE_MULTI_REGION === 'true') return true; try { - return new URL(getApiEndpoint()).hostname.endsWith('cloud.appwrite.io'); + return url.hostname.endsWith('cloud.appwrite.io'); } catch { return false; }