Skip to content

Commit 7fe851b

Browse files
committed
fix: detect registrar by nameservers
We detect cname flattening by registrar though when nameservers are rerouted legal registar stays the same. So instead we check if nameservers are cloudflare and can use cname flattening.
1 parent 013a2b5 commit 7fe851b

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

packages/domain/src/trpc/domain.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,10 @@ import { router, procedure } from "@webstudio-is/trpc-interface/index.server";
66
import { Templates } from "@webstudio-is/sdk";
77
import { db } from "../db";
88

9-
const registrars = {
10-
cloudflare: {
11-
rdap: "https://rdap.cloudflare.com/rdap/v1/domain/",
12-
cnameFlattening: true,
13-
alias: false,
14-
},
15-
/*
16-
// ALIAS record is not support by cloudflare custom domains service
17-
namecheap: {
18-
rdap: "https://rdap.namecheap.com/domain/",
19-
cnameFlattening: false,
20-
alias: true,
21-
},
22-
*/
23-
} as const;
9+
const rdap = [
10+
"https://rdap.cloudflare.com/rdap/v1/domain/",
11+
"https://rdap.namecheap.com/domain/",
12+
];
2413

2514
export const domainRouter = router({
2615
getEntriToken: procedure.query(async ({ ctx }) => {
@@ -44,13 +33,13 @@ export const domainRouter = router({
4433
.input(z.object({ domain: z.string() }))
4534
.query(async ({ input }) => {
4635
try {
47-
for (const [name, meta] of Object.entries(registrars)) {
48-
const response = await fetch(`${meta.rdap}${input.domain}`);
36+
for (const rdapEndpoint of rdap) {
37+
const response = await fetch(`${rdapEndpoint}${input.domain}`);
4938
if (response.ok) {
39+
const data = await response.text();
5040
return {
51-
name: name as keyof typeof registrars,
52-
cnameFlattening: meta.cnameFlattening,
53-
alias: meta.alias,
41+
// detect by nameservers rather than registrar url
42+
cnameFlattening: data.includes(".ns.cloudflare.com"),
5443
};
5544
}
5645
}
@@ -60,7 +49,6 @@ export const domainRouter = router({
6049
return {
6150
name: "other",
6251
cnameFlattening: false,
63-
alias: false,
6452
};
6553
}),
6654

0 commit comments

Comments
 (0)