Fix isMultiRegionSupported to accept URL parameter

This commit is contained in:
Torsten Dittmann
2025-05-16 16:31:39 +02:00
parent 99b20f4126
commit 030618196a
2 changed files with 3 additions and 4 deletions
+1 -1
View File
@@ -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`;
}
+2 -3
View File
@@ -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;
}