mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
feat: set project endpoint based on the region
This commit is contained in:
+18
-2
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user