Skip to content

Commit 957617a

Browse files
committed
Add CNAME warning for apex domains
1 parent 0ba7a6b commit 957617a

6 files changed

Lines changed: 125 additions & 97 deletions

File tree

src/routes/(console)/project-[region]-[project]/functions/function-[function]/domains/add-domain/verify-[domain]/+page.svelte

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,37 @@
2020
import Wizard from '$lib/layout/wizard.svelte';
2121
import { base } from '$app/paths';
2222
import { writable } from 'svelte/store';
23-
import { isASubdomain } from '$lib/helpers/tlds';
2423
import NameserverTable from '$lib/components/domains/nameserverTable.svelte';
2524
import RecordTable from '$lib/components/domains/recordTable.svelte';
2625
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
2726
2827
let { data } = $props();
2928
3029
const ruleId = page.url.searchParams.get('rule');
31-
const isSubDomain = $derived.by(() => isASubdomain(data.proxyRule.domain));
3230
33-
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>(getDefaultTab());
31+
const showCNAMETab = $derived(
32+
Boolean($regionalConsoleVariables._APP_DOMAIN_FUNCTIONS) &&
33+
$regionalConsoleVariables._APP_DOMAIN_FUNCTIONS !== 'localhost'
34+
);
35+
const showATab = $derived(
36+
!isCloud &&
37+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_A) &&
38+
$regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'
39+
);
40+
const showAAAATab = $derived(
41+
!isCloud &&
42+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) &&
43+
$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'
44+
);
45+
const showNSTab = isCloud;
3446
47+
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>(getDefaultTab());
3548
let routeBase = `${base}/project-${page.params.region}-${page.params.project}/functions/function-${page.params.function}/domains`;
3649
let verified: boolean | undefined = $state(undefined);
3750
const isSubmitting = writable(false);
3851
3952
function getDefaultTab() {
40-
if (isSubDomain && $regionalConsoleVariables._APP_DOMAIN_FUNCTIONS) {
41-
return 'cname';
42-
} else if (!isCloud && $regionalConsoleVariables._APP_DOMAIN_TARGET_A) {
43-
return 'a';
44-
} else if (!isCloud && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) {
45-
return 'aaaa';
46-
} else {
47-
return 'nameserver';
48-
}
53+
return showCNAMETab ? 'cname' : showATab ? 'a' : showAAAATab ? 'aaaa' : 'nameserver';
4954
}
5055
5156
async function verify() {
@@ -131,31 +136,31 @@
131136
<Layout.Stack gap="xl">
132137
<div>
133138
<Tabs.Root variant="secondary" let:root>
134-
{#if isSubDomain && !!$regionalConsoleVariables._APP_DOMAIN_FUNCTIONS && $regionalConsoleVariables._APP_DOMAIN_FUNCTIONS !== 'localhost'}
139+
{#if showCNAMETab}
135140
<Tabs.Item.Button
136141
{root}
137142
on:click={() => (selectedTab = 'cname')}
138143
active={selectedTab === 'cname'}>
139144
CNAME
140145
</Tabs.Item.Button>
141146
{/if}
142-
{#if isCloud}
147+
{#if showNSTab}
143148
<Tabs.Item.Button
144149
{root}
145150
on:click={() => (selectedTab = 'nameserver')}
146151
active={selectedTab === 'nameserver'}>
147152
Nameservers
148153
</Tabs.Item.Button>
149154
{/if}
150-
{#if !isCloud && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_A && $regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'}
155+
{#if showATab}
151156
<Tabs.Item.Button
152157
{root}
153158
on:click={() => (selectedTab = 'a')}
154159
active={selectedTab === 'a'}>
155160
A
156161
</Tabs.Item.Button>
157162
{/if}
158-
{#if !isCloud && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'}
163+
{#if showAAAATab}
159164
<Tabs.Item.Button
160165
{root}
161166
on:click={() => (selectedTab = 'aaaa')}

src/routes/(console)/project-[region]-[project]/functions/function-[function]/domains/retryDomainModal.svelte

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import { Dependencies } from '$lib/constants';
99
import type { Models } from '@appwrite.io/console';
1010
import { page } from '$app/state';
11-
import { isASubdomain } from '$lib/helpers/tlds';
1211
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
1312
import { isCloud } from '$lib/system';
1413
import { Divider, Tabs } from '@appwrite.io/pink-svelte';
@@ -23,25 +22,30 @@
2322
selectedProxyRule: Models.ProxyRule;
2423
} = $props();
2524
26-
const isSubDomain = $derived.by(() => isASubdomain(selectedProxyRule?.domain));
25+
const showCNAMETab = $derived(
26+
Boolean($regionalConsoleVariables._APP_DOMAIN_FUNCTIONS) &&
27+
$regionalConsoleVariables._APP_DOMAIN_FUNCTIONS !== 'localhost'
28+
);
29+
const showATab = $derived(
30+
!isCloud &&
31+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_A) &&
32+
$regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'
33+
);
34+
const showAAAATab = $derived(
35+
!isCloud &&
36+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) &&
37+
$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'
38+
);
39+
const showNSTab = isCloud;
2740
2841
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>(getDefaultTab());
42+
let error = $state(null);
43+
let verified = $state(false);
2944
3045
function getDefaultTab() {
31-
if (isSubDomain && $regionalConsoleVariables._APP_DOMAIN_FUNCTIONS) {
32-
return 'cname';
33-
} else if (!isCloud && $regionalConsoleVariables._APP_DOMAIN_TARGET_A) {
34-
return 'a';
35-
} else if (!isCloud && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) {
36-
return 'aaaa';
37-
} else {
38-
return 'nameserver';
39-
}
46+
return showCNAMETab ? 'cname' : showATab ? 'a' : showAAAATab ? 'aaaa' : 'nameserver';
4047
}
4148
42-
let error = $state(null);
43-
let verified = $state(false);
44-
4549
async function retryProxyRule() {
4650
try {
4751
error = null;
@@ -90,31 +94,31 @@
9094
<Modal title="Retry verification" bind:show onSubmit={retryProxyRule} bind:error>
9195
<div>
9296
<Tabs.Root variant="secondary" let:root>
93-
{#if isSubDomain && !!$regionalConsoleVariables._APP_DOMAIN_FUNCTIONS && $regionalConsoleVariables._APP_DOMAIN_FUNCTIONS !== 'localhost'}
97+
{#if showCNAMETab}
9498
<Tabs.Item.Button
9599
{root}
96100
on:click={() => (selectedTab = 'cname')}
97101
active={selectedTab === 'cname'}>
98102
CNAME
99103
</Tabs.Item.Button>
100104
{/if}
101-
{#if isCloud}
105+
{#if showNSTab}
102106
<Tabs.Item.Button
103107
{root}
104108
on:click={() => (selectedTab = 'nameserver')}
105109
active={selectedTab === 'nameserver'}>
106110
Nameservers
107111
</Tabs.Item.Button>
108112
{/if}
109-
{#if !isCloud && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_A && $regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'}
113+
{#if showATab}
110114
<Tabs.Item.Button
111115
{root}
112116
on:click={() => (selectedTab = 'a')}
113117
active={selectedTab === 'a'}>
114118
A
115119
</Tabs.Item.Button>
116120
{/if}
117-
{#if !isCloud && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'}
121+
{#if showAAAATab}
118122
<Tabs.Item.Button
119123
{root}
120124
on:click={() => (selectedTab = 'aaaa')}

src/routes/(console)/project-[region]-[project]/settings/domains/add-domain/verify-[domain]/+page.svelte

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,29 @@
2020
import Wizard from '$lib/layout/wizard.svelte';
2121
import { base } from '$app/paths';
2222
import { writable } from 'svelte/store';
23-
import { isASubdomain } from '$lib/helpers/tlds';
2423
import NameserverTable from '$lib/components/domains/nameserverTable.svelte';
2524
import RecordTable from '$lib/components/domains/recordTable.svelte';
2625
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
2726
2827
let { data } = $props();
2928
3029
const ruleId = page.url.searchParams.get('rule');
31-
const isSubDomain = $derived.by(() => isASubdomain(data.proxyRule.domain));
30+
31+
const showCNAMETab = $derived(
32+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME) &&
33+
$regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME !== 'localhost'
34+
);
35+
const showATab = $derived(
36+
!isCloud &&
37+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_A) &&
38+
$regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'
39+
);
40+
const showAAAATab = $derived(
41+
!isCloud &&
42+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) &&
43+
$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'
44+
);
45+
const showNSTab = isCloud;
3246
3347
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>(getDefaultTab());
3448
@@ -37,15 +51,7 @@
3751
const isSubmitting = writable(false);
3852
3953
function getDefaultTab() {
40-
if (isSubDomain && $regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME) {
41-
return 'cname';
42-
} else if (!isCloud && $regionalConsoleVariables._APP_DOMAIN_TARGET_A) {
43-
return 'a';
44-
} else if (!isCloud && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) {
45-
return 'aaaa';
46-
} else {
47-
return 'nameserver';
48-
}
54+
return showCNAMETab ? 'cname' : showATab ? 'a' : showAAAATab ? 'aaaa' : 'nameserver';
4955
}
5056
5157
async function verify() {
@@ -130,31 +136,31 @@
130136
<Layout.Stack gap="xl">
131137
<div>
132138
<Tabs.Root variant="secondary" let:root>
133-
{#if isSubDomain && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME && $regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME !== 'localhost'}
139+
{#if showCNAMETab}
134140
<Tabs.Item.Button
135141
{root}
136142
on:click={() => (selectedTab = 'cname')}
137143
active={selectedTab === 'cname'}>
138144
CNAME
139145
</Tabs.Item.Button>
140146
{/if}
141-
{#if isCloud}
147+
{#if showNSTab}
142148
<Tabs.Item.Button
143149
{root}
144150
on:click={() => (selectedTab = 'nameserver')}
145151
active={selectedTab === 'nameserver'}>
146152
Nameservers
147153
</Tabs.Item.Button>
148154
{/if}
149-
{#if !isCloud && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_A && $regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'}
155+
{#if showATab}
150156
<Tabs.Item.Button
151157
{root}
152158
on:click={() => (selectedTab = 'a')}
153159
active={selectedTab === 'a'}>
154160
A
155161
</Tabs.Item.Button>
156162
{/if}
157-
{#if !isCloud && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'}
163+
{#if showAAAATab}
158164
<Tabs.Item.Button
159165
{root}
160166
on:click={() => (selectedTab = 'aaaa')}

src/routes/(console)/project-[region]-[project]/settings/domains/retryDomainModal.svelte

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import { Dependencies } from '$lib/constants';
99
import type { Models } from '@appwrite.io/console';
1010
import { page } from '$app/state';
11-
import { isASubdomain } from '$lib/helpers/tlds';
1211
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
1312
import { isCloud } from '$lib/system';
1413
import { Divider, Tabs } from '@appwrite.io/pink-svelte';
@@ -23,23 +22,28 @@
2322
selectedProxyRule: Models.ProxyRule;
2423
} = $props();
2524
26-
const isSubDomain = $derived.by(() => isASubdomain(selectedProxyRule?.domain));
25+
const showCNAMETab = $derived(
26+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME) &&
27+
$regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME !== 'localhost'
28+
);
29+
const showATab = $derived(
30+
!isCloud &&
31+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_A) &&
32+
$regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'
33+
);
34+
const showAAAATab = $derived(
35+
!isCloud &&
36+
Boolean($regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) &&
37+
$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'
38+
);
39+
const showNSTab = isCloud;
2740
2841
let selectedTab = $state<'cname' | 'nameserver' | 'a' | 'aaaa'>(getDefaultTab());
29-
3042
let error = $state(null);
3143
let verified = $state(false);
3244
3345
function getDefaultTab() {
34-
if (isSubDomain && $regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME) {
35-
return 'cname';
36-
} else if (!isCloud && $regionalConsoleVariables._APP_DOMAIN_TARGET_A) {
37-
return 'a';
38-
} else if (!isCloud && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA) {
39-
return 'aaaa';
40-
} else {
41-
return 'nameserver';
42-
}
46+
return showCNAMETab ? 'cname' : showATab ? 'a' : showAAAATab ? 'aaaa' : 'nameserver';
4347
}
4448
4549
async function retryDomain() {
@@ -90,31 +94,31 @@
9094
<Modal title="Retry verification" bind:show onSubmit={retryDomain} bind:error>
9195
<div>
9296
<Tabs.Root variant="secondary" let:root>
93-
{#if isSubDomain && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME && $regionalConsoleVariables._APP_DOMAIN_TARGET_CNAME !== 'localhost'}
97+
{#if showCNAMETab}
9498
<Tabs.Item.Button
9599
{root}
96100
on:click={() => (selectedTab = 'cname')}
97101
active={selectedTab === 'cname'}>
98102
CNAME
99103
</Tabs.Item.Button>
100104
{/if}
101-
{#if isCloud}
105+
{#if showNSTab}
102106
<Tabs.Item.Button
103107
{root}
104108
on:click={() => (selectedTab = 'nameserver')}
105109
active={selectedTab === 'nameserver'}>
106110
Nameservers
107111
</Tabs.Item.Button>
108112
{/if}
109-
{#if !isCloud && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_A && $regionalConsoleVariables._APP_DOMAIN_TARGET_A !== '127.0.0.1'}
113+
{#if showATab}
110114
<Tabs.Item.Button
111115
{root}
112116
on:click={() => (selectedTab = 'a')}
113117
active={selectedTab === 'a'}>
114118
A
115119
</Tabs.Item.Button>
116120
{/if}
117-
{#if !isCloud && !!$regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA && $regionalConsoleVariables._APP_DOMAIN_TARGET_AAAA !== '::1'}
121+
{#if showAAAATab}
118122
<Tabs.Item.Button
119123
{root}
120124
on:click={() => (selectedTab = 'aaaa')}

0 commit comments

Comments
 (0)