Merge pull request #1845 from appwrite/additional-checks

Additional check with hostname
This commit is contained in:
Torsten Dittmann
2025-05-16 15:43:39 +02:00
committed by GitHub
2 changed files with 16 additions and 4 deletions
+2 -2
View File
@@ -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`;
}
+14 -2
View File
@@ -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;
}
}