Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

register domain wip

Kiran K8287f7be6a2d
diff --git a/apps/web/app/api/domains/register/route.ts b/apps/web/app/api/domains/register/route.ts
index 5269c0fdca..b6e85cff45 100644
--- a/apps/web/app/api/domains/register/route.ts
+++ b/apps/web/app/api/domains/register/route.ts
@@ -16,7 +16,13 @@ export const POST = withWorkspace(
async ({ searchParams }) => {
const { domain } = schema.parse(searchParams);
- return NextResponse.json(await registerDomain({ domain }));
+ const response = await registerDomain({ domain });
+
+ // TODO:
+ // Add domain to the workspace if registration is successful
+ // Add DNS records to the domain if registration is successful (in the background)
+
+ return NextResponse.json(response);
},
{
requiredPermissions: ["domains.write"],
diff --git a/apps/web/lib/dynadot/configure-dns.ts b/apps/web/lib/dynadot/configure-dns.ts
new file mode 100644
index 0000000000..cbff29fb8c
--- /dev/null
+++ b/apps/web/lib/dynadot/configure-dns.ts
@@ -0,0 +1,44 @@
+import z from "@/lib/zod";
+import { DYNADOT_API_KEY, DYNADOT_BASE_URL } from "./constants";
+
+const schema = z.object({
+ RegisterResponse: z.object({
+ // ResponseCode: z.enum(["0", "-1", ""]),
+ Status: z.enum(["success", "insufficient_funds"]),
+ DomainName: z.string(),
+ // Expiration: z.number(),
+ }),
+});
+
+export const configureDNS = async ({ domain }: { domain: string }) => {
+ const searchParams = new URLSearchParams({
+ key: DYNADOT_API_KEY,
+ domain: domain,
+ command: "set_dns2",
+ main_record_type0: "aaaa",
+ main_record0: "76.76.21.21",
+ });
+
+ const response = await fetch(
+ `${DYNADOT_BASE_URL}?${searchParams.toString()}`,
+ {
+ headers: {
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ },
+ );
+
+ if (!response.ok) {
+ throw new Error(`Failed to register domain: ${response.statusText}`);
+ }
+
+ const json = await response.json();
+
+ console.log("registerDomain", json);
+
+ return json;
+
+ // const data = schema.parse(json);
+
+ // return data;
+};