mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: API domains
This commit is contained in:
1 parent
2a76074087
commit
fa51e40880
11 files changed
+260
-218
No files matched your search
@@ -18,10 +18,10 @@
|
||||
<Layout.Stack direction="row" justifyContent="space-between">
|
||||
<SearchQuery search={data.search} placeholder="Search domain" />
|
||||
<Button
|
||||
href={`${base}/project-${page.params.project}/sites/site-${page.params.site}/domains/add-domain`}
|
||||
href={`${base}/project-${page.params.project}/settings/domains/add-domain`}
|
||||
on:click={() => {
|
||||
trackEvent(Click.DomainCreateClick, {
|
||||
source: 'sites_domain_overview'
|
||||
source: 'settings_domain_overview'
|
||||
});
|
||||
}}>
|
||||
<Icon icon={IconPlus} size="s" />
|
||||
@@ -53,8 +53,8 @@
|
||||
src={$app.themeInUse === 'dark'
|
||||
? `${base}/images/domains/empty-domain-dark.svg`
|
||||
: `${base}/images/domains/empty-domain-light.svg`}
|
||||
title="Use a custom domain"
|
||||
description="Make your API easier to access and integrate by assigning it a custom domain.">
|
||||
title="Use a custom domain for your API"
|
||||
description="Connect your own domain to Appwrite, so your API is accessible from a custom URL instead of the default Appwrite endpoint.">
|
||||
<svelte:fragment slot="actions">
|
||||
<Button
|
||||
external
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { RuleTrigger, sdk } from '$lib/stores/sdk';
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import type { PageLoad } from './$types';
|
||||
import { getSearch } from '$lib/helpers/load';
|
||||
@@ -24,7 +24,7 @@ export const load: PageLoad = async ({ depends, url, route }) => {
|
||||
|
||||
return {
|
||||
rules: await sdk.forProject.proxy.listRules(
|
||||
[Query.equal('type', RuleType.API)],
|
||||
[Query.equal('type', RuleType.API), Query.equal('trigger', RuleTrigger.MANUAL)],
|
||||
search || undefined
|
||||
),
|
||||
offset,
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import { Button, Form, InputDomain } from '$lib/elements/forms';
|
||||
import { Wizard } from '$lib/layout';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Fieldset, Layout } from '@appwrite.io/pink-svelte';
|
||||
import { goto, invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
const routeBase = `${base}/project-${page.params.project}/settings/domains`;
|
||||
|
||||
//TODO: enable once combo box is fixed
|
||||
// let { data } = $props();
|
||||
|
||||
let formComponent: Form;
|
||||
let isSubmitting = $state(writable(false));
|
||||
|
||||
let domainName = $state('');
|
||||
|
||||
async function addDomain() {
|
||||
try {
|
||||
const rule = await sdk.forProject.proxy.createAPIRule(domainName);
|
||||
if (rule?.status === 'verified') {
|
||||
await goto(routeBase);
|
||||
await invalidate(Dependencies.DOMAINS);
|
||||
} else {
|
||||
await goto(`${routeBase}/add-domain/verify-${domainName}?rule=${rule.$id}`);
|
||||
await invalidate(Dependencies.DOMAINS);
|
||||
}
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Wizard title="Add domain" href={routeBase} column columnSize="s" confirmExit>
|
||||
<Form bind:this={formComponent} onSubmit={addDomain} bind:isSubmitting>
|
||||
<Layout.Stack gap="xxl">
|
||||
<Fieldset legend="Domain">
|
||||
<!-- <Input.ComboBox
|
||||
label="Domain"
|
||||
id="domain"
|
||||
name="domain"
|
||||
bind:value={domain}
|
||||
options={data.domains.rules.map((domain) => ({
|
||||
label: domain.domain,
|
||||
value: domain.domain
|
||||
}))}
|
||||
required
|
||||
placeholder="appwrite.example.com" /> -->
|
||||
<InputDomain
|
||||
label="Domain"
|
||||
id="domain"
|
||||
bind:value={domainName}
|
||||
required
|
||||
placeholder="appwrite.example.com" />
|
||||
</Fieldset>
|
||||
</Layout.Stack>
|
||||
</Form>
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary href={routeBase}>Cancel</Button>
|
||||
<Button on:click={() => formComponent.triggerSubmit()} bind:disabled={$isSubmitting}>
|
||||
Add
|
||||
</Button>
|
||||
</svelte:fragment>
|
||||
</Wizard>
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { RuleTrigger, RuleType } from '$lib/stores/sdk';
|
||||
import { Dependencies } from '$lib/constants.js';
|
||||
|
||||
export const load = async ({ depends }) => {
|
||||
depends(Dependencies.DOMAINS);
|
||||
|
||||
const [rules] = await Promise.all([
|
||||
sdk.forProject.proxy.listRules([
|
||||
Query.equal('type', RuleType.API),
|
||||
Query.equal('trigger', RuleTrigger.MANUAL)
|
||||
])
|
||||
]);
|
||||
|
||||
return {
|
||||
rules
|
||||
};
|
||||
};
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
<script lang="ts">
|
||||
import { IconGlobeAlt } from '@appwrite.io/pink-icons-svelte';
|
||||
import { Card, Divider, Icon, Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
import VerificationFieldset from './verificationFieldset.svelte';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { goto, invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { page } from '$app/state';
|
||||
import Wizard from '$lib/layout/wizard.svelte';
|
||||
import { base } from '$app/paths';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
const ruleId = page.url.searchParams.get('rule');
|
||||
const routeBase = `${base}/project-${page.params.project}/settings/domains`;
|
||||
let selectedTab: 'cname' | 'nameserver' = $state();
|
||||
let verified = $state(false);
|
||||
|
||||
let isSubmitting = $state(writable(false));
|
||||
|
||||
async function verify() {
|
||||
const isNewDomain =
|
||||
data.domainsList.domains.findIndex((rule) => rule.domain === page.params.domain) === -1;
|
||||
try {
|
||||
if (selectedTab === 'cname') {
|
||||
const ruleData = await sdk.forProject.proxy.updateRuleVerification(ruleId);
|
||||
verified = ruleData.status === 'verified';
|
||||
} else if (isNewDomain && isCloud) {
|
||||
const domainData = await sdk.forConsole.domains.create(
|
||||
$organization.$id,
|
||||
page.params.domain
|
||||
);
|
||||
verified = domainData.nameservers.toLocaleLowerCase() === 'appwrite';
|
||||
}
|
||||
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: 'Domain added successfully'
|
||||
});
|
||||
await goto(routeBase);
|
||||
await invalidate(Dependencies.DOMAINS);
|
||||
await invalidate(Dependencies.SITES_DOMAINS);
|
||||
} catch (error) {
|
||||
verified = false;
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function back() {
|
||||
if (ruleId) {
|
||||
await sdk.forProject.proxy.deleteRule(ruleId);
|
||||
}
|
||||
await goto(`${routeBase}/add-domain?domain=${page.params.domain}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Wizard title="Add domain" href={routeBase} column columnSize="s">
|
||||
<Form onSubmit={verify} bind:isSubmitting>
|
||||
<Layout.Stack gap="xxl">
|
||||
<Card.Base radius="s" padding="s">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
justifyContent="space-between"
|
||||
alignItems="center"
|
||||
gap="xs">
|
||||
<Layout.Stack direction="row" alignItems="center" gap="xs">
|
||||
<Icon icon={IconGlobeAlt} color="--fgcolor-neutral-primary" />
|
||||
|
||||
<Typography.Text variation="m-500" color="--fgcolor-neutral-primary">
|
||||
{page.params.domain}
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<Button secondary on:click={back}>Change</Button>
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
|
||||
<VerificationFieldset domain={page.params.domain} {verified} bind:selectedTab>
|
||||
<Divider />
|
||||
<Layout.Stack direction="row" justifyContent="flex-end">
|
||||
<div>
|
||||
<Button submit disabled={$isSubmitting}>Verify</Button>
|
||||
</div>
|
||||
</Layout.Stack>
|
||||
</VerificationFieldset>
|
||||
</Layout.Stack>
|
||||
</Form>
|
||||
</Wizard>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Dependencies } from '$lib/constants.js';
|
||||
import { isCloud } from '$lib/system';
|
||||
import type { Domain, DomainsList } from '$lib/sdk/domains.js';
|
||||
|
||||
export const load = async ({ parent, depends, params }) => {
|
||||
depends(Dependencies.DOMAINS);
|
||||
|
||||
let domain: Domain;
|
||||
let domainsList: DomainsList;
|
||||
if (isCloud) {
|
||||
[domain, domainsList] = await Promise.all([
|
||||
sdk.forConsole.domains.get(params.domain),
|
||||
sdk.forConsole.domains.list()
|
||||
]);
|
||||
}
|
||||
|
||||
return {
|
||||
domain,
|
||||
domainsList
|
||||
};
|
||||
};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import CnameTable from '$lib/components/domains/cnameTable.svelte';
|
||||
import NameserverTable from '$lib/components/domains/nameserverTable.svelte';
|
||||
import { isCloud, isSelfHosted } from '$lib/system';
|
||||
import { Divider, Fieldset, Layout, Tabs } from '@appwrite.io/pink-svelte';
|
||||
|
||||
export let domain: string;
|
||||
export let verified: boolean;
|
||||
|
||||
$: isSubDomain = domain?.split('.')?.length >= 3;
|
||||
export let selectedTab: 'cname' | 'nameserver' =
|
||||
isSubDomain || isSelfHosted ? 'cname' : 'nameserver';
|
||||
</script>
|
||||
|
||||
<Fieldset legend="Verification">
|
||||
<Layout.Stack gap="xl">
|
||||
<div>
|
||||
<Tabs.Root variant="secondary" let:root>
|
||||
{#if isSubDomain}
|
||||
<Tabs.Item.Button
|
||||
{root}
|
||||
on:click={() => (selectedTab = 'cname')}
|
||||
active={selectedTab === 'cname'}>
|
||||
CNAME
|
||||
</Tabs.Item.Button>
|
||||
{/if}
|
||||
{#if isCloud}
|
||||
<Tabs.Item.Button
|
||||
{root}
|
||||
on:click={() => (selectedTab = 'nameserver')}
|
||||
active={selectedTab === 'nameserver'}>
|
||||
Nameservers
|
||||
</Tabs.Item.Button>
|
||||
{/if}
|
||||
</Tabs.Root>
|
||||
<Divider />
|
||||
</div>
|
||||
{#if selectedTab === 'cname' && isSubDomain}
|
||||
<CnameTable {domain} {verified} />
|
||||
{:else if isCloud}
|
||||
<NameserverTable {domain} {verified} />
|
||||
{/if}
|
||||
<slot />
|
||||
</Layout.Stack>
|
||||
</Fieldset>
|
||||
@@ -1,72 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import { Wizard } from '$lib/layout';
|
||||
import { Fieldset, Layout } from '@appwrite.io/pink-svelte';
|
||||
import Button from '$lib/elements/forms/button.svelte';
|
||||
import Form from '$lib/elements/forms/form.svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import { InputDomain } from '$lib/elements/forms';
|
||||
import { goto } from '$app/navigation';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
|
||||
let showExitModal = false;
|
||||
let formComponent: Form;
|
||||
let isSubmitting = writable(false);
|
||||
|
||||
export let data;
|
||||
|
||||
let domain = data.domain;
|
||||
|
||||
async function create() {
|
||||
try {
|
||||
if (data.$id) {
|
||||
await sdk.forProject.proxy.deleteRule(data.$id);
|
||||
}
|
||||
|
||||
const value = await sdk.forProject.proxy.createAPIRule(domain);
|
||||
|
||||
trackEvent(Submit.DomainCreate);
|
||||
goto(`${base}/project-${page.params.project}/settings/domains/create/${value.$id}`);
|
||||
} catch (e) {
|
||||
trackError(e.message, Submit.DomainCreate);
|
||||
throw new Error(e.message);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Wizard
|
||||
title="Create custom domain"
|
||||
href={`${base}/project-${page.params.project}/settings/domains`}
|
||||
bind:showExitModal
|
||||
column
|
||||
hideFooter
|
||||
confirmExit>
|
||||
<Form bind:this={formComponent} onSubmit={create} bind:isSubmitting>
|
||||
<Layout.Stack gap="xxl">
|
||||
<Fieldset legend="Configuration">
|
||||
<Layout.Stack gap="l" alignItems="flex-end">
|
||||
<Layout.Stack gap="s">
|
||||
<InputDomain
|
||||
id="domain"
|
||||
label="Domain"
|
||||
placeholder="appwrite.example.com"
|
||||
autocomplete={false}
|
||||
required
|
||||
bind:value={domain} />
|
||||
</Layout.Stack>
|
||||
<Button
|
||||
fullWidthMobile
|
||||
size="s"
|
||||
submit
|
||||
forceShowLoader
|
||||
on:click={() => formComponent.triggerSubmit()}
|
||||
disabled={$isSubmitting}>
|
||||
Create domain
|
||||
</Button>
|
||||
</Layout.Stack>
|
||||
</Fieldset>
|
||||
</Layout.Stack>
|
||||
</Form>
|
||||
</Wizard>
|
||||
@@ -1,6 +0,0 @@
|
||||
export const load = async ({ url }) => {
|
||||
const domain = url.searchParams.get('domain');
|
||||
const $id = url.searchParams.get('$id');
|
||||
|
||||
return { domain, $id };
|
||||
};
|
||||
@@ -1,128 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import { Wizard } from '$lib/layout';
|
||||
import {
|
||||
Card,
|
||||
Fieldset,
|
||||
Icon,
|
||||
Layout,
|
||||
Spinner,
|
||||
Status,
|
||||
Typography
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import Button from '$lib/elements/forms/button.svelte';
|
||||
import Form from '$lib/elements/forms/form.svelte';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { writable } from 'svelte/store';
|
||||
import Retry from '$lib/pages/domains/wizard/retry.svelte';
|
||||
import { IconClock } from '@appwrite.io/pink-icons-svelte';
|
||||
|
||||
let retrying = false;
|
||||
let showExitModal = false;
|
||||
let isSubmitting = writable(false);
|
||||
|
||||
export let data;
|
||||
|
||||
let domain = data.domain;
|
||||
|
||||
function onSubmit() {}
|
||||
|
||||
async function retry() {
|
||||
try {
|
||||
retrying = true;
|
||||
domain = await sdk.forProject.proxy.updateRuleVerification(domain.$id);
|
||||
invalidate(Dependencies.FUNCTION_DOMAINS);
|
||||
addNotification({
|
||||
message:
|
||||
domain.status === 'unverified'
|
||||
? 'Domain certificate has been generated successfully'
|
||||
: 'Domain has been verified successfully',
|
||||
type: 'success'
|
||||
});
|
||||
trackEvent(Submit.DomainUpdateVerification);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
trackError(error, Submit.DomainUpdateVerification);
|
||||
} finally {
|
||||
retrying = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Wizard
|
||||
title={data.domain.domain}
|
||||
href={`${base}/project-${page.params.project}/settings/domains/`}
|
||||
bind:showExitModal
|
||||
column>
|
||||
<Form {onSubmit} bind:isSubmitting>
|
||||
<Layout.Stack gap="xxl">
|
||||
<Card.Base padding="s">
|
||||
<Layout.Stack direction="row" justifyContent="space-between" alignItems="center">
|
||||
<Typography.Text variant="m-500">{data.domain.domain}</Typography.Text>
|
||||
<Button
|
||||
secondary
|
||||
size="s"
|
||||
href={`${base}/project-${page.params.project}/settings/domains/create?domain=${data.domain.domain}&$id=${data.domain.$id}`}
|
||||
>Change</Button>
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
<Fieldset legend="DNS">
|
||||
<Layout.Stack gap="l" alignItems="flex-end">
|
||||
<Layout.Stack>
|
||||
{#if data.domain.status === 'created'}
|
||||
<Retry bind:domain showTitle={false} />
|
||||
{:else}
|
||||
<div class="u-flex u-gap-8 u-cross-center">
|
||||
<span class="icon-check u-color-text-success" aria-hidden="true"
|
||||
></span>
|
||||
<p class="u-stretch">Domain verified</p>
|
||||
</div>
|
||||
{/if}
|
||||
<Card.Base variant="secondary" padding="s">
|
||||
<Layout.Stack direction="row" gap="s" alignItems="center">
|
||||
{#if domain.status === 'verifying'}
|
||||
<Spinner size="s" />
|
||||
<p class="u-stretch">Generating certificate</p>
|
||||
{:else if domain.status === 'verified'}
|
||||
<Status status="complete" label="Certificate generated" />
|
||||
{:else}
|
||||
<Icon icon={IconClock} size="s" />
|
||||
Certificate generation will begin after domain verification
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Card.Base>
|
||||
</Layout.Stack>
|
||||
{#if data.domain.status === 'created'}
|
||||
<Button
|
||||
fullWidthMobile
|
||||
size="s"
|
||||
submit
|
||||
secondary
|
||||
forceShowLoader
|
||||
on:click={retry}
|
||||
disabled={retrying}>
|
||||
Retry
|
||||
</Button>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Fieldset>
|
||||
</Layout.Stack>
|
||||
</Form>
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Button
|
||||
fullWidthMobile
|
||||
secondary
|
||||
href={`${base}/project-${page.params.project}/settings/domains`}>
|
||||
Go to Domains
|
||||
</Button>
|
||||
</svelte:fragment>
|
||||
</Wizard>
|
||||
@@ -1,6 +0,0 @@
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
|
||||
export const load = async ({ params }) => {
|
||||
const domain = await sdk.forProject.proxy.getRule(params.domain);
|
||||
return { domain };
|
||||
};
|
||||
Reference in new issue
Block a user