Skip to content

Commit f3f8768

Browse files
authored
Merge pull request #2826 from appwrite/fix-domains
Get first domain from list
2 parents 576736f + fa62bc7 commit f3f8768

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/lib/helpers/domains.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ import { Query } from '@appwrite.io/console';
44
import { getApexDomain } from './tlds';
55
import { isCloud } from '$lib/system';
66

7+
/**
8+
* Normalizes console variables by extracting the first domain from comma-separated domain lists.
9+
* This handles the backend sending `_APP_DOMAIN_SITES` (and similar fields) as comma-separated values.
10+
*/
11+
export function normalizeConsoleVariables(
12+
variables: Models.ConsoleVariables
13+
): Models.ConsoleVariables {
14+
return {
15+
...variables,
16+
_APP_DOMAIN_SITES: getFirstDomain(variables._APP_DOMAIN_SITES)
17+
};
18+
}
19+
20+
/**
21+
* Extracts the first domain from a potentially comma-separated list of domains.
22+
*/
23+
function getFirstDomain(domainList: string | undefined): string {
24+
if (!domainList) return '';
25+
return domainList.split(',')[0].trim();
26+
}
27+
728
export async function createRecord(record: Partial<Models.DnsRecord>, domainId: string) {
829
switch (record.type) {
930
case 'A':

src/routes/(console)/+layout.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Dependencies } from '$lib/constants';
55
import { Platform, Query } from '@appwrite.io/console';
66
import { makePlansMap } from '$lib/helpers/billing';
77
import { plansInfo as plansInfoStore } from '$lib/stores/billing';
8+
import { normalizeConsoleVariables } from '$lib/helpers/domains';
89

910
export const load: LayoutLoad = async ({ depends, parent }) => {
1011
const { organizations, plansInfo } = await parent();
@@ -22,7 +23,7 @@ export const load: LayoutLoad = async ({ depends, parent }) => {
2223
platform: Platform.Appwrite
2324
});
2425

25-
const [preferences, plansArray, versionData, consoleVariables] = await Promise.all([
26+
const [preferences, plansArray, versionData, rawConsoleVariables] = await Promise.all([
2627
sdk.forConsole.account.getPrefs(),
2728
plansArrayPromise,
2829
fetch(`${endpoint}/health/version`, {
@@ -31,6 +32,8 @@ export const load: LayoutLoad = async ({ depends, parent }) => {
3132
sdk.forConsole.console.variables()
3233
]);
3334

35+
const consoleVariables = normalizeConsoleVariables(rawConsoleVariables);
36+
3437
let fallbackPlansInfoArray = plansInfo;
3538
if (!fallbackPlansInfoArray) {
3639
fallbackPlansInfoArray = makePlansMap(plansArray);

src/routes/(console)/project-[region]-[project]/+layout.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { loadAvailableRegions } from '$routes/(console)/regions';
1111
import { type Models, Platform } from '@appwrite.io/console';
1212
import { redirect } from '@sveltejs/kit';
1313
import { resolve } from '$app/paths';
14+
import { normalizeConsoleVariables } from '$lib/helpers/domains';
1415

1516
export const load: LayoutLoad = async ({ params, depends, parent }) => {
1617
const { plansInfo, organizations, preferences: prefs } = await parent();
@@ -27,7 +28,7 @@ export const load: LayoutLoad = async ({ params, depends, parent }) => {
2728
// organization can be null if not in the filtered list!
2829
const includedInBasePlans = plansInfo.has(organization?.billingPlanId);
2930

30-
const [org, regionalConsoleVariables, rolesResult] = await Promise.all([
31+
const [org, rawRegionalConsoleVariables, rolesResult] = await Promise.all([
3132
!organization
3233
? // TODO: @itznotabug - teams.get with Models.Organization?
3334
(sdk.forConsole.teams.get({ teamId: project.teamId }) as Promise<Models.Organization>)
@@ -42,6 +43,8 @@ export const load: LayoutLoad = async ({ params, depends, parent }) => {
4243
loadAvailableRegions(project.teamId)
4344
]);
4445

46+
const regionalConsoleVariables = normalizeConsoleVariables(rawRegionalConsoleVariables);
47+
4548
if (!organization) organization = org;
4649

4750
// not the right organization project based on platform,

0 commit comments

Comments
 (0)