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.

add search domain API

Kiran Ke6045d53eac9
diff --git a/apps/web/.env.example b/apps/web/.env.example
index 526548585c..d7f6b3ec83 100644
--- a/apps/web/.env.example
+++ b/apps/web/.env.example
@@ -119,4 +119,6 @@ PANGEA_API_KEY=
SLACK_APP_INSTALL_URL=
SLACK_CLIENT_ID=
SLACK_CLIENT_SECRET=
-SLACK_SIGNING_SECRET=
\ No newline at end of file
+SLACK_SIGNING_SECRET=
+
+DYNADOT_API_KEY=
\ No newline at end of file
diff --git a/apps/web/app/api/domains/search/route.ts b/apps/web/app/api/domains/search/route.ts
new file mode 100644
index 0000000000..5bd567633b
--- /dev/null
+++ b/apps/web/app/api/domains/search/route.ts
@@ -0,0 +1,15 @@
+import { withWorkspace } from "@/lib/auth";
+import { searchDomains } from "@/lib/dynadot/search-domains";
+import { NextResponse } from "next/server";
+
+// GET /api/domains/search - search the domain
+export const GET = withWorkspace(
+ async ({ workspace }) => {
+ const domains = await searchDomains("test");
+
+ return NextResponse.json(domains);
+ },
+ {
+ requiredPermissions: ["domains.read"],
+ },
+);
diff --git a/apps/web/lib/dynadot/constants.ts b/apps/web/lib/dynadot/constants.ts
new file mode 100644
index 0000000000..b0846e727c
--- /dev/null
+++ b/apps/web/lib/dynadot/constants.ts
@@ -0,0 +1,2 @@
+export const DYNADOT_BASE_URL = "https://api.dynadot.com/api3.json";
+export const DYNADOT_API_KEY = process.env.DYNADOT_API_KEY || "";
diff --git a/apps/web/lib/dynadot/search-domains.ts b/apps/web/lib/dynadot/search-domains.ts
new file mode 100644
index 0000000000..8f22c80a6c
--- /dev/null
+++ b/apps/web/lib/dynadot/search-domains.ts
@@ -0,0 +1,24 @@
+import { DYNADOT_API_KEY, DYNADOT_BASE_URL } from "./constants";
+
+console.log({DYNADOT_API_KEY, DYNADOT_BASE_URL})
+
+export const searchDomains = async (keyword: string) => {
+ const searchParams = new URLSearchParams({
+ key: DYNADOT_API_KEY,
+ command: "search",
+ domain0: keyword,
+ domain1: keyword,
+ show_price: "1",
+ currency: "USD",
+ });
+
+ const response = await fetch(
+ `${DYNADOT_BASE_URL}?${searchParams.toString()}`,
+ );
+
+ if (!response.ok) {
+ throw new Error(`Failed to search domains: ${response.statusText}`);
+ }
+
+ return await response.json();
+};