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.

move to edge

Steven Tey3c0c37d464f3
diff --git a/apps/web/app/[domain]/stats/[key]/page.tsx b/apps/web/app/[domain]/stats/[key]/page.tsx
index 666678f48f..b4eb6b7f99 100644
--- a/apps/web/app/[domain]/stats/[key]/page.tsx
+++ b/apps/web/app/[domain]/stats/[key]/page.tsx
@@ -1,4 +1,4 @@
-import { getDomainOrLink } from "@/lib/api/links";
+import { getDomainOrLink } from "@/lib/planetscale";
import Stats from "@/ui/stats";
import { constructMetadata } from "@dub/utils";
import { notFound } from "next/navigation";
diff --git a/apps/web/app/api/edge/stats/[endpoint]/route.ts b/apps/web/app/api/edge/stats/[endpoint]/route.ts
index 87e3f4da33..8a339a9830 100644
--- a/apps/web/app/api/edge/stats/[endpoint]/route.ts
+++ b/apps/web/app/api/edge/stats/[endpoint]/route.ts
@@ -1,7 +1,6 @@
import { exceededLimitError } from "@/lib/api/errors";
-import { getDomainOrLink } from "@/lib/api/links";
import { isBlacklistedReferrer } from "@/lib/edge-config";
-import { getProjectViaEdge } from "@/lib/planetscale";
+import { getDomainOrLink, getProjectViaEdge } from "@/lib/planetscale";
import { getStats } from "@/lib/stats";
import { ratelimit } from "@/lib/upstash";
import {
diff --git a/apps/web/app/api/og/stats/route.tsx b/apps/web/app/api/og/stats/route.tsx
index f76b7856e9..14e0966685 100644
--- a/apps/web/app/api/og/stats/route.tsx
+++ b/apps/web/app/api/og/stats/route.tsx
@@ -1,4 +1,4 @@
-import { getDomainOrLink } from "@/lib/api/links";
+import { getDomainOrLink } from "@/lib/planetscale";
import { getStats } from "@/lib/stats";
import { DUB_LOGO, nFormatter, truncate } from "@dub/utils";
import { ImageResponse } from "next/og";
diff --git a/apps/web/app/api/stats/route.ts b/apps/web/app/api/stats/route.ts
index a1b4f38186..58dbfc278c 100644
--- a/apps/web/app/api/stats/route.ts
+++ b/apps/web/app/api/stats/route.ts
@@ -1,5 +1,5 @@
-import { getDomainOrLink } from "@/lib/api/links";
import { withAuth } from "@/lib/auth";
+import { getDomainOrLink } from "@/lib/planetscale";
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 6b0876104a..7a650c66e8 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -21,7 +21,7 @@ import {
} from "@dub/utils";
import cloudinary from "cloudinary";
import { Session } from "../auth";
-import { getDomainViaEdge, getLinkViaEdge } from "../planetscale";
+import { getLinkViaEdge } from "../planetscale";
import { recordLink } from "../tinybird";
import { LinkProps, ProjectProps, RedisLinkProps } from "../types";
@@ -711,23 +711,3 @@ export async function transferLink({
},
});
}
-
-export async function getDomainOrLink({
- domain,
- key,
-}: {
- domain: string;
- key?: string;
-}) {
- if (!key || key === "_root") {
- const data = await getDomainViaEdge(domain);
- if (!data) return null;
- return {
- ...data,
- key: "_root",
- url: data?.target,
- };
- } else {
- return await getLinkViaEdge(domain, key);
- }
-}
diff --git a/apps/web/lib/planetscale.ts b/apps/web/lib/planetscale.ts
index 8e1a6af874..bdb6ae6171 100644
--- a/apps/web/lib/planetscale.ts
+++ b/apps/web/lib/planetscale.ts
@@ -60,3 +60,23 @@ export const getLinkViaEdge = async (domain: string, key: string) => {
})
: null;
};
+
+export async function getDomainOrLink({
+ domain,
+ key,
+}: {
+ domain: string;
+ key?: string;
+}) {
+ if (!key || key === "_root") {
+ const data = await getDomainViaEdge(domain);
+ if (!data) return null;
+ return {
+ ...data,
+ key: "_root",
+ url: data?.target,
+ };
+ } else {
+ return await getLinkViaEdge(domain, key);
+ }
+}