Skip to content

Commit 9c4ad14

Browse files
committed
feat(dns): rework provider management and support all record types
Providers, domains and records now each have their own page instead of a stack of modals. A provider opens its domains as cards, with the record count loading separately so the domains appear right away. A domain opens its records as a table with search, type filter and pagination. Creating or editing a record happens in a panel that slides in next to the table. The type list was capped at A and CNAME in the zod schema, so widening the dropdown alone would not have worked. AAAA, MX, TXT, NS, SRV, CAA and PTR work now. MX carries a priority that Cloudflare takes as a separate field and Route53 takes inline in the value, so the Cloudflare client splits it out on write and puts it back on read. The form keeps one value field for both providers. Cloudflare proxy status is now editable and visible. A, AAAA and CNAME records get a Proxied / DNS only toggle in the form and a cloud icon in the table. The proxy field only goes to the API when the caller sets it, so an update from another path cannot silently disable the proxy. Tests cover the MX priority round trip and the proxy rules in the Cloudflare client.
1 parent 5ff0c26 commit 9c4ad14

19 files changed

Lines changed: 1756 additions & 621 deletions

File tree

‎apps/dokploy/__test__/dns/cloudflare.test.ts‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,154 @@ describe("cloudflareClient.listRecords", () => {
8787
});
8888
});
8989

90+
describe("cloudflareClient MX priority", () => {
91+
it("inlines the priority into the content when listing", async () => {
92+
mockFetch.mockResolvedValue(
93+
cfSuccess([
94+
{
95+
id: "mx-1",
96+
type: "MX",
97+
name: "example.com",
98+
content: "mail.example.com",
99+
ttl: 300,
100+
priority: 20,
101+
},
102+
]),
103+
);
104+
105+
const records = await cloudflareClient.listRecords(config, "zone-1");
106+
107+
expect(records[0]?.content).toBe("20 mail.example.com");
108+
});
109+
110+
it("splits the priority back out when writing", async () => {
111+
mockFetch
112+
.mockResolvedValueOnce(cfSuccess([]))
113+
.mockResolvedValueOnce(cfSuccess({ id: "mx-1" }));
114+
115+
await cloudflareClient.upsertRecord(config, {
116+
zoneId: "zone-1",
117+
type: "MX",
118+
name: "example.com",
119+
content: "20 mail.example.com",
120+
});
121+
122+
const [, init] = mockFetch.mock.calls[1] as [string, RequestInit];
123+
expect(JSON.parse(init.body as string)).toMatchObject({
124+
content: "mail.example.com",
125+
priority: 20,
126+
});
127+
});
128+
129+
it("falls back to priority 10 when the content has no leading number", async () => {
130+
mockFetch
131+
.mockResolvedValueOnce(cfSuccess([]))
132+
.mockResolvedValueOnce(cfSuccess({ id: "mx-1" }));
133+
134+
await cloudflareClient.upsertRecord(config, {
135+
zoneId: "zone-1",
136+
type: "MX",
137+
name: "example.com",
138+
content: "mail.example.com",
139+
});
140+
141+
const [, init] = mockFetch.mock.calls[1] as [string, RequestInit];
142+
expect(JSON.parse(init.body as string)).toMatchObject({
143+
content: "mail.example.com",
144+
priority: 10,
145+
});
146+
});
147+
148+
it("leaves non-MX content untouched", async () => {
149+
mockFetch
150+
.mockResolvedValueOnce(cfSuccess([]))
151+
.mockResolvedValueOnce(cfSuccess({ id: "txt-1" }));
152+
153+
await cloudflareClient.upsertRecord(config, {
154+
zoneId: "zone-1",
155+
type: "TXT",
156+
name: "example.com",
157+
content: "10 not-a-priority",
158+
});
159+
160+
const [, init] = mockFetch.mock.calls[1] as [string, RequestInit];
161+
const body = JSON.parse(init.body as string);
162+
expect(body.content).toBe("10 not-a-priority");
163+
expect(body.priority).toBeUndefined();
164+
});
165+
});
166+
167+
describe("cloudflareClient proxy status", () => {
168+
it("sends the proxy status for proxiable types", async () => {
169+
mockFetch
170+
.mockResolvedValueOnce(cfSuccess([]))
171+
.mockResolvedValueOnce(cfSuccess({ id: "a-1" }));
172+
173+
await cloudflareClient.upsertRecord(config, {
174+
zoneId: "zone-1",
175+
type: "A",
176+
name: "app.example.com",
177+
content: "1.2.3.4",
178+
proxied: true,
179+
});
180+
181+
const [, init] = mockFetch.mock.calls[1] as [string, RequestInit];
182+
expect(JSON.parse(init.body as string).proxied).toBe(true);
183+
});
184+
185+
it("omits the proxy status for types Cloudflare cannot proxy", async () => {
186+
mockFetch
187+
.mockResolvedValueOnce(cfSuccess([]))
188+
.mockResolvedValueOnce(cfSuccess({ id: "txt-1" }));
189+
190+
await cloudflareClient.upsertRecord(config, {
191+
zoneId: "zone-1",
192+
type: "TXT",
193+
name: "example.com",
194+
content: "hello",
195+
proxied: true,
196+
});
197+
198+
const [, init] = mockFetch.mock.calls[1] as [string, RequestInit];
199+
expect(JSON.parse(init.body as string).proxied).toBeUndefined();
200+
});
201+
202+
it("leaves the proxy status untouched when the caller does not set it", async () => {
203+
mockFetch
204+
.mockResolvedValueOnce(cfSuccess([]))
205+
.mockResolvedValueOnce(cfSuccess({ id: "a-1" }));
206+
207+
await cloudflareClient.upsertRecord(config, {
208+
zoneId: "zone-1",
209+
type: "A",
210+
name: "app.example.com",
211+
content: "1.2.3.4",
212+
});
213+
214+
const [, init] = mockFetch.mock.calls[1] as [string, RequestInit];
215+
expect("proxied" in JSON.parse(init.body as string)).toBe(false);
216+
});
217+
218+
it("returns the proxy status when listing records", async () => {
219+
mockFetch.mockResolvedValue(
220+
cfSuccess([
221+
{
222+
id: "a-1",
223+
type: "A",
224+
name: "app.example.com",
225+
content: "1.2.3.4",
226+
ttl: 1,
227+
proxied: true,
228+
},
229+
]),
230+
);
231+
232+
const records = await cloudflareClient.listRecords(config, "zone-1");
233+
234+
expect(records[0]?.proxied).toBe(true);
235+
});
236+
});
237+
90238
describe("cloudflareClient.upsertRecord", () => {
91239
it("creates a record when none exists for the name/type", async () => {
92240
mockFetch
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useRouter } from "next/router";
2+
import { useEffect, useState } from "react";
3+
4+
let lastDepth: number | null = null;
5+
6+
const depthOf = (path: string) =>
7+
path.split("?")[0]!.split("/").filter(Boolean).length;
8+
9+
export const DnsPageTransition = ({
10+
children,
11+
}: {
12+
children: React.ReactNode;
13+
}) => {
14+
const { asPath } = useRouter();
15+
const depth = depthOf(asPath);
16+
const [direction] = useState(() =>
17+
lastDepth !== null && depth < lastDepth ? "back" : "forward",
18+
);
19+
20+
useEffect(() => {
21+
lastDepth = depth;
22+
}, [depth]);
23+
24+
return (
25+
<div
26+
data-direction={direction}
27+
className="t-page-enter flex w-full flex-col gap-4"
28+
>
29+
{children}
30+
</div>
31+
);
32+
};

0 commit comments

Comments
 (0)