From e9adda3cd543a4a9e551df49dd8aafa0dfdb8290 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 11 Nov 2024 20:51:38 +0100 Subject: [PATCH 1/9] feat: set project endpoint based on the region --- src/lib/stores/sdk.ts | 20 +++++++++++++++++-- .../(console)/project-[project]/+layout.ts | 5 ++++- src/routes/+layout.ts | 4 +++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index c4b3189ddd..b02674bdb0 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -25,11 +25,27 @@ import { Billing } from '../sdk/billing'; import { Backups } from '../sdk/backups'; import { Sources } from '$lib/sdk/sources'; -export function getApiEndpoint(): string { +export function getApiEndpoint(region?: string): string { if (VARS.APPWRITE_ENDPOINT) return VARS.APPWRITE_ENDPOINT; - return globalThis?.location?.origin + '/v1'; + let protocol = globalThis?.location?.protocol; + let hostname = globalThis?.location?.hostname; + let subdomain = getSubdomain(region); + return `${protocol}://${subdomain}${hostname}/v1`; } +const getSubdomain = (region?: string) => { + switch (region) { + case 'fra': + return 'fra.'; + case 'syd': + return 'syd.'; + case 'nyc': + return 'nyc.'; + default: + return ''; + } +}; + const endpoint = getApiEndpoint(); const clientConsole = new Client(); diff --git a/src/routes/(console)/project-[project]/+layout.ts b/src/routes/(console)/project-[project]/+layout.ts index 57df9d5285..11bbdbddc9 100644 --- a/src/routes/(console)/project-[project]/+layout.ts +++ b/src/routes/(console)/project-[project]/+layout.ts @@ -1,5 +1,5 @@ import { Dependencies } from '$lib/constants'; -import { sdk } from '$lib/stores/sdk'; +import { getApiEndpoint, sdk } from '$lib/stores/sdk'; import { error } from '@sveltejs/kit'; import type { LayoutLoad } from './$types'; import { preferences } from '$lib/stores/preferences'; @@ -35,6 +35,9 @@ export const load: LayoutLoad = async ({ params, depends }) => { } } + console.log(getApiEndpoint(project.region)); + sdk.forProject.client.setEndpoint(getApiEndpoint(project.region)); + return { project, organization, diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 77fd3e8b13..13d2668348 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -1,7 +1,7 @@ import '@appwrite.io/pink'; import '@appwrite.io/pink-icons'; import 'tippy.js/dist/tippy.css'; -import { sdk } from '$lib/stores/sdk'; +import { getApiEndpoint, sdk } from '$lib/stores/sdk'; import { redirect } from '@sveltejs/kit'; import { Dependencies } from '$lib/constants'; import type { LayoutLoad } from './$types'; @@ -14,6 +14,8 @@ export const ssr = false; export const load: LayoutLoad = async ({ depends, url, route }) => { depends(Dependencies.ACCOUNT); + console.log(getApiEndpoint()); + sdk.forProject.client.setEndpoint(getApiEndpoint()); const [account, error] = (await sdk.forConsole.account .get() From c6a011eaeb60cbd238fc14755b6fedae3f8accb3 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 11 Nov 2024 20:53:01 +0100 Subject: [PATCH 2/9] feat: set project endpoint based on the region --- src/routes/+layout.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 13d2668348..74ca47f3bf 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -14,6 +14,7 @@ export const ssr = false; export const load: LayoutLoad = async ({ depends, url, route }) => { depends(Dependencies.ACCOUNT); + console.log(getApiEndpoint()); sdk.forProject.client.setEndpoint(getApiEndpoint()); From c86d6aad209b515dcf3413b743d56579d2819780 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 11 Nov 2024 23:17:27 +0100 Subject: [PATCH 3/9] feat: linter --- src/routes/+layout.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 74ca47f3bf..ffdaa77bec 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -14,7 +14,7 @@ export const ssr = false; export const load: LayoutLoad = async ({ depends, url, route }) => { depends(Dependencies.ACCOUNT); - + console.log(getApiEndpoint()); sdk.forProject.client.setEndpoint(getApiEndpoint()); From b70850786f382bd1f85b863b60dd16577b88e32c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 11 Nov 2024 23:19:46 +0100 Subject: [PATCH 4/9] feat: linter --- src/lib/stores/sdk.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index b02674bdb0..8361ce8697 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -27,9 +27,9 @@ import { Sources } from '$lib/sdk/sources'; export function getApiEndpoint(region?: string): string { if (VARS.APPWRITE_ENDPOINT) return VARS.APPWRITE_ENDPOINT; - let protocol = globalThis?.location?.protocol; - let hostname = globalThis?.location?.hostname; - let subdomain = getSubdomain(region); + const protocol = globalThis?.location?.protocol; + const hostname = globalThis?.location?.hostname; + const subdomain = getSubdomain(region); return `${protocol}://${subdomain}${hostname}/v1`; } From 2f744a88491c24bbc6c2ad84f60b5534b749a4e7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 12 Nov 2024 09:34:05 +0100 Subject: [PATCH 5/9] feat: add constants for regions --- src/lib/stores/sdk.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 8361ce8697..c9da6e7e1b 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -33,14 +33,22 @@ export function getApiEndpoint(region?: string): string { return `${protocol}://${subdomain}${hostname}/v1`; } +const REGION_FRA = 'fra'; +const REGION_SYD = 'syd'; +const REGION_NYC = 'nyc'; + +const SUBDOMAIN_FRA = 'fra.'; +const SUBDOMAIN_SYD = 'syd.'; +const SUBDOMAIN_NYC = 'nyc.'; + const getSubdomain = (region?: string) => { switch (region) { - case 'fra': - return 'fra.'; - case 'syd': - return 'syd.'; - case 'nyc': - return 'nyc.'; + case REGION_FRA: + return SUBDOMAIN_FRA; + case REGION_SYD: + return SUBDOMAIN_SYD; + case REGION_NYC: + return SUBDOMAIN_NYC; default: return ''; } From 2c4af1f44ae7f58afa86a003ddba4c29bd17cb58 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 12 Nov 2024 09:34:38 +0100 Subject: [PATCH 6/9] feat: add constants for regions --- src/lib/constants.ts | 8 ++++++++ src/lib/stores/sdk.ts | 9 +-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 2fc9104284..128a5e5905 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -2,6 +2,14 @@ export const PAGE_LIMIT = 12; // default page limit export const CARD_LIMIT = 6; // default card limit export const INTERVAL = 5 * 60000; // default interval to check for feedback +export const REGION_FRA = 'fra'; +export const REGION_SYD = 'syd'; +export const REGION_NYC = 'nyc'; + +export const SUBDOMAIN_FRA = 'fra.'; +export const SUBDOMAIN_SYD = 'syd.'; +export const SUBDOMAIN_NYC = 'nyc.'; + export enum Dependencies { FACTORS = 'dependency:factors', IDENTITIES = 'dependency:identities', diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index c9da6e7e1b..30baf49f10 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -24,6 +24,7 @@ import { import { Billing } from '../sdk/billing'; import { Backups } from '../sdk/backups'; import { Sources } from '$lib/sdk/sources'; +import { REGION_FRA, REGION_NYC, REGION_SYD, SUBDOMAIN_FRA, SUBDOMAIN_NYC, SUBDOMAIN_SYD } from '$lib/constants'; export function getApiEndpoint(region?: string): string { if (VARS.APPWRITE_ENDPOINT) return VARS.APPWRITE_ENDPOINT; @@ -33,14 +34,6 @@ export function getApiEndpoint(region?: string): string { return `${protocol}://${subdomain}${hostname}/v1`; } -const REGION_FRA = 'fra'; -const REGION_SYD = 'syd'; -const REGION_NYC = 'nyc'; - -const SUBDOMAIN_FRA = 'fra.'; -const SUBDOMAIN_SYD = 'syd.'; -const SUBDOMAIN_NYC = 'nyc.'; - const getSubdomain = (region?: string) => { switch (region) { case REGION_FRA: From d02f97fa12d8c8c6dce4353050deffd54fde51b3 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 12 Nov 2024 09:43:17 +0100 Subject: [PATCH 7/9] feat: linter --- src/lib/stores/sdk.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 30baf49f10..a41d8f34bb 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -24,7 +24,14 @@ import { import { Billing } from '../sdk/billing'; import { Backups } from '../sdk/backups'; import { Sources } from '$lib/sdk/sources'; -import { REGION_FRA, REGION_NYC, REGION_SYD, SUBDOMAIN_FRA, SUBDOMAIN_NYC, SUBDOMAIN_SYD } from '$lib/constants'; +import { + REGION_FRA, + REGION_NYC, + REGION_SYD, + SUBDOMAIN_FRA, + SUBDOMAIN_NYC, + SUBDOMAIN_SYD +} from '$lib/constants'; export function getApiEndpoint(region?: string): string { if (VARS.APPWRITE_ENDPOINT) return VARS.APPWRITE_ENDPOINT; From 88b63902493766baefc17e2a0523e5a33b76f660 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 12 Nov 2024 10:48:16 +0100 Subject: [PATCH 8/9] chore: update endpoint --- src/lib/stores/sdk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index a41d8f34bb..eca17b2efa 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -38,7 +38,7 @@ export function getApiEndpoint(region?: string): string { const protocol = globalThis?.location?.protocol; const hostname = globalThis?.location?.hostname; const subdomain = getSubdomain(region); - return `${protocol}://${subdomain}${hostname}/v1`; + return `${protocol}//${subdomain}${hostname}/v1`; } const getSubdomain = (region?: string) => { From d667129f54f9d7b3ddf5e95b486ea04c4dc22c5e Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 12 Nov 2024 16:41:27 +0100 Subject: [PATCH 9/9] feat: update domains for staging --- src/lib/constants.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 128a5e5905..8f99945834 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -6,9 +6,9 @@ export const REGION_FRA = 'fra'; export const REGION_SYD = 'syd'; export const REGION_NYC = 'nyc'; -export const SUBDOMAIN_FRA = 'fra.'; -export const SUBDOMAIN_SYD = 'syd.'; -export const SUBDOMAIN_NYC = 'nyc.'; +export const SUBDOMAIN_FRA = 'fra-'; +export const SUBDOMAIN_SYD = 'syd-'; +export const SUBDOMAIN_NYC = 'nyc-'; export enum Dependencies { FACTORS = 'dependency:factors',