Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

feat: improve automatic domain configuration (#5289)

Bogdan Chadkin3cc2f3be1e96
diff --git a/apps/builder/app/builder/features/topbar/add-domain.tsx b/apps/builder/app/builder/features/topbar/add-domain.tsx
index e5575c5ee3..5b92828045 100644
--- a/apps/builder/app/builder/features/topbar/add-domain.tsx
+++ b/apps/builder/app/builder/features/topbar/add-domain.tsx
@@ -14,6 +14,7 @@ import type { Project } from "@webstudio-is/project";
import { useId, useOptimistic, useRef, useState } from "react";
import { TerminalIcon } from "@webstudio-is/icons";
import { nativeClient } from "~/shared/trpc/trpc-client";
+import { extractCname } from "./cname";
type DomainsAddProps = {
projectId: Project["id"];
@@ -38,7 +39,7 @@ export const AddDomain = ({
// Will be automatically reset on action end
setIsPendingOptimistic(true);
- const domain = formData.get("domain")?.toString() ?? "";
+ let domain = formData.get("domain")?.toString() ?? "";
const validationResult = validateDomain(domain);
if (validationResult.success === false) {
@@ -46,6 +47,18 @@ export const AddDomain = ({
return;
}
+ // detect provider only when root domain is specified
+ if (extractCname(domain) === "@") {
+ const registrar = await nativeClient.domain.findDomainRegistrar.query({
+ domain,
+ });
+ // enforce www subdomain when no support for cname flattening
+ // and root cname can conflict with MX or NS
+ if (!registrar.cnameFlattening) {
+ domain = `www.${domain}`;
+ }
+ }
+
const result = await nativeClient.domain.create.mutate({
domain,
projectId,
diff --git a/apps/builder/app/builder/features/topbar/domain-checkbox.tsx b/apps/builder/app/builder/features/topbar/domain-checkbox.tsx
index c68aeae817..849a3ff339 100644
--- a/apps/builder/app/builder/features/topbar/domain-checkbox.tsx
+++ b/apps/builder/app/builder/features/topbar/domain-checkbox.tsx
@@ -20,7 +20,7 @@ interface DomainCheckboxProps {
disabled?: boolean;
}
-const DomainCheckbox = (props: DomainCheckboxProps) => {
+export const DomainCheckbox = (props: DomainCheckboxProps) => {
const hasProPlan = useStore($userPlanFeatures).hasProPlan;
const project = useStore($project);
@@ -78,5 +78,3 @@ const DomainCheckbox = (props: DomainCheckboxProps) => {
</div>
);
};
-
-export default DomainCheckbox;
diff --git a/apps/builder/app/builder/features/topbar/domains.tsx b/apps/builder/app/builder/features/topbar/domains.tsx
index b3db280988..a84f62f497 100644
--- a/apps/builder/app/builder/features/topbar/domains.tsx
+++ b/apps/builder/app/builder/features/topbar/domains.tsx
@@ -21,6 +21,7 @@ import {
} from "@webstudio-is/icons";
import { CollapsibleDomainSection } from "./collapsible-domain-section";
import {
+ Fragment,
startTransition,
useEffect,
useOptimistic,
@@ -34,12 +35,13 @@ import { useStore } from "@nanostores/react";
import { $publisherHost } from "~/shared/nano-states";
import { extractCname } from "./cname";
import { useEffectEvent } from "~/shared/hook-utils/effect-event";
-import DomainCheckbox from "./domain-checkbox";
+import { DomainCheckbox } from "./domain-checkbox";
import { CopyToClipboard } from "~/builder/shared/copy-to-clipboard";
import { RelativeTime } from "~/builder/shared/relative-time";
export type Domain = Project["domainsVirtual"][number];
-type DomainStatus = Project["domainsVirtual"][number]["status"];
+
+type DomainStatus = Domain["status"];
const InputEllipsis = styled(InputField, {
"&>input": {
@@ -164,23 +166,28 @@ const StatusIcon = (props: { projectDomain: Domain; isLoading: boolean }) => {
);
};
-const DomainItem = (props: {
+const DomainItem = ({
+ initiallyOpen,
+ projectDomain,
+ project,
+ refresh,
+}: {
initiallyOpen: boolean;
projectDomain: Domain;
- refresh: () => Promise<void>;
project: Project;
+ refresh: () => Promise<void>;
}) => {
const timeSinceLastUpdateMs =
- Date.now() - new Date(props.projectDomain.updatedAt).getTime();
+ Date.now() - new Date(projectDomain.updatedAt).getTime();
const DAY_IN_MS = 24 * 60 * 60 * 1000;
- const status = props.projectDomain.verified
- ? (`VERIFIED_${props.projectDomain.status}` as `VERIFIED_${DomainStatus}`)
+ const status = projectDomain.verified
+ ? (`VERIFIED_${projectDomain.status}` as `VERIFIED_${DomainStatus}`)
: `UNVERIFIED`;
const [isStatusLoading, setIsStatusLoading] = useState(
- props.initiallyOpen ||
+ initiallyOpen ||
status === "VERIFIED_ACTIVE" ||
timeSinceLastUpdateMs > DAY_IN_MS
? false
@@ -195,8 +202,8 @@ const DomainItem = (props: {
const handleRemoveDomain = async () => {
setIsRemoveInProgress(true);
const result = await nativeClient.domain.remove.mutate({
- projectId: props.projectDomain.projectId,
- domainId: props.projectDomain.domainId,
+ projectId: projectDomain.projectId,
+ domainId: projectDomain.domainId,
});
if (result.success === false) {
@@ -204,7 +211,7 @@ const DomainItem = (props: {
return;
}
- await props.refresh();
+ await refresh();
};
const [verifyError, setVerifyError] = useState<string | undefined>(undefined);
@@ -214,8 +221,8 @@ const DomainItem = (props: {
setIsCheckStateInProgress(true);
const verifyResult = await nativeClient.domain.verify.mutate({
- projectId: props.projectDomain.projectId,
- domainId: props.projectDomain.domainId,
+ projectId: projectDomain.projectId,
+ domainId: projectDomain.domainId,
});
if (verifyResult.success === false) {
@@ -223,7 +230,7 @@ const DomainItem = (props: {
return;
}
- await props.refresh();
+ await refresh();
});
const [updateStatusError, setUpdateStatusError] = useState<
@@ -235,8 +242,8 @@ const DomainItem = (props: {
setIsCheckStateInProgress(true);
const updateStatusResult = await nativeClient.domain.updateStatus.mutate({
- projectId: props.projectDomain.projectId,
- domain: props.projectDomain.domain,
+ projectId: projectDomain.projectId,
+ domain: projectDomain.domain,
});
setIsStatusLoading(false);
@@ -246,7 +253,7 @@ const DomainItem = (props: {
return;
}
- await props.refresh();
+ await refresh();
});
const onceRef = useRef(false);
@@ -272,67 +279,60 @@ const DomainItem = (props: {
});
}, [status, handleVerify, handleUpdateStatus, isStatusLoading]);
- const publisherHost = useStore($publisherHost);
- const cnameEntryName = extractCname(props.projectDomain.domain);
- const cnameEntryValue = `${props.projectDomain.cname}.customers.${publisherHost}`;
-
- const txtEntryName =
- cnameEntryName === "@"
- ? "_webstudio_is"
- : `_webstudio_is.${cnameEntryName}`;
-
- const domainStatus = getStatus(props.projectDomain);
-
- const cnameRecord = {
- type: "CNAME",
- host: cnameEntryName,
- value: cnameEntryValue,
- ttl: 300,
- } as const;
-
- const txtRecord = {
- type: "TXT",
- host: txtEntryName,
- value: props.projectDomain.expectedTxtRecord,
- ttl: 300,
- } as const;
-
- const dnsRecords = [cnameRecord, txtRecord];
+ const domainStatus = getStatus(projectDomain);
const { isVerifiedActive, text } = getStatusText({
- projectDomain: props.projectDomain,
+ projectDomain,
isLoading: false,
});
+ const publisherHost = useStore($publisherHost);
+ const cname = extractCname(projectDomain.domain);
+ const dnsRecords = [
+ {
+ type: "CNAME",
+ host: cname,
+ value: `${projectDomain.cname}.customers.${publisherHost}`,
+ ttl: 300,
+ } as const,
+ {
+ type: "TXT",
+ host: cname === "@" ? "_webstudio_is" : `_webstudio_is.${cname}`,
+ value: projectDomain.expectedTxtRecord,
+ ttl: 300,
+ } as const,
+ ];
+
return (
<CollapsibleDomainSection
prefix={
<DomainCheckbox
- buildId={props.projectDomain.latestBuildVirtual?.buildId}
+ buildId={projectDomain.latestBuildVirtual?.buildId}
defaultChecked={
- props.projectDomain.latestBuildVirtual?.buildId != null &&
- props.projectDomain.latestBuildVirtual?.buildId ===
- props.project.latestBuildVirtual?.buildId
+ projectDomain.latestBuildVirtual?.buildId != null &&
+ projectDomain.latestBuildVirtual?.buildId ===
+ project.latestBuildVirtual?.buildId
}
- domain={props.projectDomain.domain}
+ domain={projectDomain.domain}
disabled={domainStatus !== "VERIFIED_ACTIVE"}
/>
}
- initiallyOpen={props.initiallyOpen}
- title={props.projectDomain.domain}
+ initiallyOpen={initiallyOpen}
+ title={projectDomain.domain}
suffix={
<Grid flow="column">
<StatusIcon
isLoading={isStatusLoading}
- projectDomain={props.projectDomain}
+ projectDomain={projectDomain}
/>
- <Tooltip content={`Proceed to ${props.projectDomain.domain}`}>
+ <Tooltip content={`Proceed to ${projectDomain.domain}`}>
<IconButton
+ type="button"
tabIndex={-1}
disabled={status !== "VERIFIED_ACTIVE"}
onClick={(event) => {
- const url = new URL(`https://${props.projectDomain.domain}`);
+ const url = new URL(`https://${projectDomain.domain}`);
window.open(url.href, "_blank");
event.preventDefault();
}}
@@ -423,67 +423,45 @@ const DomainItem = (props: {
<Grid
gap={2}
- css={{
- gridTemplateColumns: `${theme.spacing[18]} 1fr 1fr`,
- }}
+ css={{ gridTemplateColumns: `${theme.spacing[18]} 1fr 1fr` }}
>
- <Text color="subtle" variant={"titles"}>
+ <Text color="subtle" variant="titles">
TYPE
</Text>
- <Text color="subtle" variant={"titles"}>
+ <Text color="subtle" variant="titles">
NAME
</Text>
- <Text color="subtle" variant={"titles"}>
+ <Text color="subtle" variant="titles">
VALUE
</Text>
- <InputEllipsis readOnly value="CNAME" />
- <InputEllipsis
- readOnly
- value={cnameRecord.host}
- suffix={
- <CopyToClipboard text={cnameRecord.host}>
- <NestedInputButton type="button">
- <CopyIcon />
- </NestedInputButton>
- </CopyToClipboard>
- }
- />
- <InputEllipsis
- readOnly
- value={cnameRecord.value}
- suffix={
- <CopyToClipboard text={cnameRecord.value}>
- <NestedInputButton type="button">
- <CopyIcon />
- </NestedInputButton>
- </CopyToClipboard>
- }
- />
-
- <InputEllipsis readOnly value="TXT" />
- <InputEllipsis
- readOnly
- value={txtRecord.host}
- suffix={
- <CopyToClipboard text={txtRecord.host}>
- <NestedInputButton type="button">
- <CopyIcon />
- </NestedInputButton>
- </CopyToClipboard>
- }
- />
- <InputEllipsis
- readOnly
- value={txtRecord.value}
- suffix={
- <CopyToClipboard text={txtRecord.value}>
- <NestedInputButton type="button">
- <CopyIcon />
- </NestedInputButton>
- </CopyToClipboard>
- }
- />
+ {dnsRecords.map((record, index) => (
+ <Fragment key={index}>
+ <InputEllipsis readOnly value={record.type} />
+ <InputEllipsis
+ readOnly
+ value={record.host}
+ suffix={
+ <CopyToClipboard text={record.host}>
+ <NestedInputButton type="button">
+ <CopyIcon />
+ </NestedInputButton>
+ </CopyToClipboard>
+ }
+ />
+ <InputEllipsis
+ readOnly
+ value={record.value}
+ suffix={
+ <CopyToClipboard text={record.value}>
+ <NestedInputButton type="button">
+ <CopyIcon />
+ </NestedInputButton>
+ </CopyToClipboard>
+ }
+ />
+ </Fragment>
+ ))}
</Grid>
<Grid
@@ -500,7 +478,7 @@ const DomainItem = (props: {
<Entri
dnsRecords={dnsRecords}
- domain={props.projectDomain.domain}
+ domain={projectDomain.domain}
onClose={() => {
// Sometimes Entri modal dialog hangs even if it's successful,
// until they fix that, we'll just refresh the status here on every onClose event
diff --git a/apps/builder/app/builder/features/topbar/entri.tsx b/apps/builder/app/builder/features/topbar/entri.tsx
index cffbf3c01f..eacb1dcd6f 100644
--- a/apps/builder/app/builder/features/topbar/entri.tsx
+++ b/apps/builder/app/builder/features/topbar/entri.tsx
@@ -1,38 +1,118 @@
-import { Button, Text } from "@webstudio-is/design-system";
-import {
- useEntri,
- entriGlobalStyles,
- type DnsRecord,
- type EntriCloseDetail,
-} from "~/shared/entri/entri";
-
-export const Entri = ({
- dnsRecords,
- domain,
- onClose,
-}: {
- dnsRecords: DnsRecord[];
+import * as entri from "entrijs";
+import { useEffect, useState } from "react";
+import { useStore } from "@nanostores/react";
+import { globalCss, Button, Text, toast } from "@webstudio-is/design-system";
+import { trpcClient } from "~/shared/trpc/trpc-client";
+import { $userPlanFeatures } from "~/shared/nano-states";
+import { extractCname } from "./cname";
+
+// https://developers.entri.com/docs/install
+type DnsRecord = {
+ type: "CNAME" | "ALIAS" | "TXT";
+ host: string;
+ value: string;
+ ttl: number;
+};
+
+type EntriCloseEvent = CustomEvent<entri.EntriCloseEventDetail>;
+
+declare global {
+ // https://developers.entri.com/docs/integrate-with-dns-providers
+ interface WindowEventMap {
+ onEntriClose: EntriCloseEvent;
+ }
+}
+
+/**
+ * Our FloatingPanelPopover adds pointerEvents: "none" to the body.
+ * We open the entry dialog from the popover, so we need to allow pointer events on the entri dialog.
+ */
+const entriGlobalStyles = globalCss({
+ body: {
+ "&>#entriApp": {
+ pointerEvents: "auto",
+ },
+ },
+});
+
+type EntriProps = {
domain: string;
- onClose: (detail: EntriCloseDetail) => void;
-}) => {
+ dnsRecords: DnsRecord[];
+ onClose: (detail: entri.EntriCloseEventDetail) => void;
+};
+
+const useEntri = ({ domain, dnsRecords, onClose }: EntriProps) => {
+ const [isOpen, setIsOpen] = useState(false);
+
+ const {
+ load: entriTokenLoad,
+ data: entriTokenData,
+ error: entriTokenSystemError,
+ } = trpcClient.domain.getEntriToken.useQuery();
+
+ useEffect(() => {
+ const handleOnEntriClose = (event: EntriCloseEvent) => {
+ if (event.detail.domain === domain) {
+ onClose(event.detail);
+ setIsOpen(false);
+ }
+ };
+ window.addEventListener("onEntriClose", handleOnEntriClose, false);
+ return () => {
+ window.removeEventListener("onEntriClose", handleOnEntriClose, false);
+ };
+ }, [domain, onClose]);
+
+ const showDialog = () => {
+ setIsOpen(true);
+ entriTokenLoad(undefined, async (data) => {
+ if (data.success) {
+ await entri.showEntri({
+ applicationId: data.applicationId,
+ token: data.token,
+ dnsRecords,
+ prefilledDomain: domain,
+ // add redirect to www only when registered domain has www subdomain
+ wwwRedirect: extractCname(domain) === "www",
+ });
+ }
+ });
+ };
+
+ return {
+ isOpen,
+ showDialog,
+ error:
+ entriTokenSystemError ??
+ (entriTokenData?.success === false ? entriTokenData.error : undefined),
+ };
+};
+
+export const Entri = ({ domain, dnsRecords, onClose }: EntriProps) => {
entriGlobalStyles();
+ const { hasProPlan } = useStore($userPlanFeatures);
const { error, isOpen, showDialog } = useEntri({
- onClose,
domain,
dnsRecords,
+ onClose,
});
-
return (
<>
{error !== undefined && <Text color="destructive">{error}</Text>}
-
<Button
disabled={isOpen}
color="neutral"
css={{ width: "100%", flexShrink: 0 }}
type="button"
onClick={() => {
- showDialog();
+ // @todo temporary for testing
+ if (hasProPlan) {
+ showDialog();
+ } else {
+ toast.error(
+ "Please upgrade to the Pro plan or higher to use automatic domain configuration."
+ );
+ }
}}
>
Configure automatically
diff --git a/apps/builder/app/builder/features/topbar/publish.tsx b/apps/builder/app/builder/features/topbar/publish.tsx
index 94af66c6f5..1b8debca6d 100644
--- a/apps/builder/app/builder/features/topbar/publish.tsx
+++ b/apps/builder/app/builder/features/topbar/publish.tsx
@@ -83,7 +83,7 @@ import {
parseComponentName,
type Templates,
} from "@webstudio-is/sdk";
-import DomainCheckbox, { domainToPublishName } from "./domain-checkbox";
+import { DomainCheckbox, domainToPublishName } from "./domain-checkbox";
import { CopyToClipboard } from "~/builder/shared/copy-to-clipboard";
import { $openProjectSettings } from "~/shared/nano-states/project-settings";
import { RelativeTime } from "~/builder/shared/relative-time";
@@ -188,12 +188,13 @@ const ChangeProjectDomain = ({
<Tooltip
content={
<Text css={{ wordBreak: "break-all" }}>
- Proceed to ${pageUrl.toString()}
+ Proceed to {pageUrl.toString()}
</Text>
}
variant="wrapped"
>
<IconButton
+ type="button"
tabIndex={-1}
onClick={(event) => {
window.open(pageUrl, "_blank");
@@ -1242,6 +1243,7 @@ export const PublishButton = ({ projectId }: PublishProps) => {
suffix={
<PopoverTitleActions>
<IconButton
+ type="button"
onClick={() => {
$openProjectSettings.set("publish");
}}
diff --git a/apps/builder/app/services/trcp-router.server.ts b/apps/builder/app/services/trcp-router.server.ts
index 1805d9370a..f40b874159 100644
--- a/apps/builder/app/services/trcp-router.server.ts
+++ b/apps/builder/app/services/trcp-router.server.ts
@@ -1,9 +1,9 @@
import { router } from "@webstudio-is/trpc-interface/index.server";
-import { marketplaceRouter } from "../shared/marketplace/router.server";
import { domainRouter } from "@webstudio-is/domain/index.server";
import { projectRouter } from "@webstudio-is/project/index.server";
import { authorizationTokenRouter } from "@webstudio-is/authorization-token/index.server";
import { dashboardProjectRouter } from "@webstudio-is/dashboard/index.server";
+import { marketplaceRouter } from "../shared/marketplace/router.server";
import { logoutRouter } from "./logout-router.server";
export const appRouter = router({
diff --git a/apps/builder/app/shared/entri/entri.ts b/apps/builder/app/shared/entri/entri.ts
deleted file mode 100644
index eac003e12f..0000000000
--- a/apps/builder/app/shared/entri/entri.ts
+++ /dev/null
@@ -1,158 +0,0 @@
-import useScript from "react-script-hook";
-import { globalCss } from "@webstudio-is/design-system";
-import { useCallback, useEffect, useRef, useState } from "react";
-import { trpcClient } from "../trpc/trpc-client";
-
-const scriptAttributes = {
- async: true,
- defer: true,
- importance: "low",
- src: "https://cdn.goentri.com/entri.js",
-};
-
-// https://developers.entri.com/docs/install
-export type DnsRecord = {
- type: "CNAME" | "TXT";
- host: string;
- value: string;
- ttl: number;
-};
-
-// https://developers.entri.com/docs/integrate-with-dns-providers
-export type EntriCloseDetail = {
- domain: string;
- lastStatus:
- | "FINISHED_SUCCESSFULLY"
- | "IN_PROGRESS"
- | "EXISTING_RECORDS"
- | "LOGIN"
- | "MANUAL_CONFIGURATION"
- | "EXIT_WITH_ERROR"
- | "DKIM_SETUP";
-
- provider: string;
- setupType: "automatic" | "manual" | "sharedLogin" | null;
- success: boolean;
-};
-
-declare global {
- interface Window {
- // https://developers.entri.com/docs/api-reference
- entri?: {
- showEntri: (options: {
- applicationId: string;
- token: string;
- dnsRecords: DnsRecord[];
- prefilledDomain: string;
- }) => void;
- };
- }
-
- // https://developers.entri.com/docs/integrate-with-dns-providers
- interface WindowEventMap {
- onEntriClose: CustomEvent<EntriCloseDetail>;
- }
-}
-
-/**
- * Our FloatingPanelPopover adds pointerEvents: "none" to the body.
- * We open the entry dialog from the popover, so we need to allow pointer events on the entri dialog.
- */
-export const entriGlobalStyles = globalCss({
- body: {
- "&>#entriApp": {
- pointerEvents: "all",
- },
- },
-});
-
-type UseEntriProps = {
- domain: string;
- onClose: (detail: EntriCloseDetail) => void;
- dnsRecords: DnsRecord[];
-};
-
-export const useEntri = ({ domain, dnsRecords, onClose }: UseEntriProps) => {
- const [isScriptLoading, scriptLoadingError] = useScript(scriptAttributes);
- const [error, setError] = useState<string | undefined>(undefined);
- const [isOpen, setIsOpen] = useState(false);
- const showDialogInternalRef = useRef<
- undefined | ((token: string, applicationId: string) => void)
- >(undefined);
-
- const {
- load: entriTokenLoad,
- data: entriTokenData,
- error: entriTokenSystemError,
- } = trpcClient.domain.getEntriToken.useQuery();
-
- useEffect(() => {
- const handleOnEntriClose = (event: CustomEvent<EntriCloseDetail>) => {
- if (event.detail.domain !== domain) {
- return;
- }
-
- onClose(event.detail);
- setIsOpen(false);
- };
-
- window.addEventListener("onEntriClose", handleOnEntriClose, false);
-
- return () => {
- window.removeEventListener("onEntriClose", handleOnEntriClose);
- };
- }, [domain, onClose]);
-
- const showDialogInternal = useCallback(
- (token: string, applicationId: string) => {
- const entri = window.entri;
-
- if (entri === undefined) {
- if (isScriptLoading) {
- setError("Entri is not loaded, try again later");
- return;
- }
-
- setError("Entri is not loaded");
- return;
- }
-
- entri.showEntri({
- applicationId,
- token,
- dnsRecords,
- prefilledDomain: domain,
- });
- },
- [dnsRecords, domain, isScriptLoading]
- );
-
- showDialogInternalRef.current = showDialogInternal;
-
- const showDialog = useCallback(() => {
- setIsOpen(true);
- entriTokenLoad(undefined, (data) => {
- if (data.success === false) {
- return;
- }
-
- if (showDialogInternalRef.current === undefined) {
- return;
- }
-
- const { token, applicationId } = data;
-
- showDialogInternalRef.current(token, applicationId);
- });
- }, [entriTokenLoad]);
-
- return {
- isOpen,
- showDialog,
- error:
- error ??
- entriTokenSystemError ??
- scriptLoadingError?.message ??
- (entriTokenData?.success === false ? entriTokenData.error : undefined),
- };
-};
diff --git a/apps/builder/package.json b/apps/builder/package.json
index 6dc3d55362..471bf9273a 100644
--- a/apps/builder/package.json
+++ b/apps/builder/package.json
@@ -91,6 +91,7 @@
"css-tree": "^2.3.1",
"debug": "^4.3.7",
"downshift": "^6.1.7",
+ "entrijs": "^0.0.11",
"fast-deep-equal": "^3.1.3",
"immer": "^10.1.1",
"immerhin": "^0.10.0",
@@ -109,7 +110,6 @@
"react-colorful": "^5.6.1",
"react-dom": "18.3.0-canary-14898b6a9-20240318",
"react-error-boundary": "^5.0.0",
- "react-script-hook": "^1.7.2",
"remix-auth": "^3.7.0",
"remix-auth-form": "^1.5.0",
"remix-auth-github": "^1.7.0",
diff --git a/packages/domain/src/trpc/domain.ts b/packages/domain/src/trpc/domain.ts
index 88eebe04f6..9bc73fbcfb 100644
--- a/packages/domain/src/trpc/domain.ts
+++ b/packages/domain/src/trpc/domain.ts
@@ -6,6 +6,22 @@ import { router, procedure } from "@webstudio-is/trpc-interface/index.server";
import { Templates } from "@webstudio-is/sdk";
import { db } from "../db";
+const registrars = {
+ cloudflare: {
+ rdap: "https://rdap.cloudflare.com/rdap/v1/domain/",
+ cnameFlattening: true,
+ alias: false,
+ },
+ /*
+ // ALIAS record is not support by cloudflare custom domains service
+ namecheap: {
+ rdap: "https://rdap.namecheap.com/domain/",
+ cnameFlattening: false,
+ alias: true,
+ },
+ */
+} as const;
+
export const domainRouter = router({
getEntriToken: procedure.query(async ({ ctx }) => {
try {
@@ -24,6 +40,30 @@ export const domainRouter = router({
}
}),
+ findDomainRegistrar: procedure
+ .input(z.object({ domain: z.string() }))
+ .query(async ({ input }) => {
+ try {
+ for (const [name, meta] of Object.entries(registrars)) {
+ const response = await fetch(`${meta.rdap}${input.domain}`);
+ if (response.ok) {
+ return {
+ name: name as keyof typeof registrars,
+ cnameFlattening: meta.cnameFlattening,
+ alias: meta.alias,
+ };
+ }
+ }
+ } catch {
+ // empty block
+ }
+ return {
+ name: "other",
+ cnameFlattening: false,
+ alias: false,
+ };
+ }),
+
project: procedure
.input(z.object({ projectId: z.string() }))
.query(async ({ input, ctx }) => {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8bb0be8fc4..45ade67600 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -334,6 +334,9 @@ importers:
downshift:
specifier: ^6.1.7
version: 6.1.7([email protected])
+ entrijs:
+ specifier: ^0.0.11
+ version: 0.0.11
fast-deep-equal:
specifier: ^3.1.3
version: 3.1.3
@@ -388,9 +391,6 @@ importers:
react-error-boundary:
specifier: ^5.0.0
version: 5.0.0([email protected])
- react-script-hook:
- specifier: ^1.7.2
remix-auth:
specifier: ^3.7.0
@@ -6483,6 +6483,9 @@ packages:
resolution: {integrity: sha512-aKstq2TDOndCn4diEyp9Uq/Flu2i1GlLkc6XIDQSDMuaFE3OPW5OphLCyQ5SpSJZTb4reN+kTcYru5yIfXoRPw==}
engines: {node: '>=0.12'}
+ resolution: {integrity: sha512-ufH4h0JdumikGIHuVQjP6uKJMG00Yv7Av0ZsBvM7PicejO8e9eRAxXKUdIHqoo1ZqogFrquDmmP63x3T0djHlQ==}
+
resolution: {integrity: sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
@@ -8445,12 +8448,6 @@ packages:
react-dom:
optional: true
- resolution: {integrity: sha512-fhyCEfXb94fag34UPRF0zry1XGwmVY+79iibWwTqAoOiCzYJQOYTiWJ7CnqglA9tMSV8g45cQpHCMcBwr7dwhA==}
- peerDependencies:
- react: 18.3.0-canary-14898b6a9-20240318
- react-dom: 18.3.0-canary-14898b6a9-20240318
-
resolution: {integrity: sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA==}
peerDependencies:
@@ -14107,6 +14104,10 @@ snapshots:
+ dependencies:
+ react: 18.3.0-canary-14898b6a9-20240318
+
@@ -16605,11 +16606,6 @@ snapshots:
optionalDependencies:
react-dom: 18.3.0-canary-14898b6a9-20240318([email protected])
- dependencies:
- react: 18.3.0-canary-14898b6a9-20240318
- react-dom: 18.3.0-canary-14898b6a9-20240318([email protected])
-
dependencies:
object-assign: 4.1.1