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 rate limits for demo links

Steven Teyba404d6f0081
diff --git a/apps/web/app/api/analytics/edge/[endpoint]/route.ts b/apps/web/app/api/analytics/edge/[endpoint]/route.ts
index 625eaf4a0d..681f48e9d0 100644
--- a/apps/web/app/api/analytics/edge/[endpoint]/route.ts
+++ b/apps/web/app/api/analytics/edge/[endpoint]/route.ts
@@ -8,12 +8,12 @@ import { getIdentityHash } from "@/lib/edge";
import { isBlacklistedReferrer } from "@/lib/edge-config";
import { getDomainOrLink, getProjectViaEdge } from "@/lib/planetscale";
import { ratelimit } from "@/lib/upstash";
-import { DEMO_LINK_ID, DUB_PROJECT_ID, getSearchParams } from "@dub/utils";
-import { NextResponse, type NextRequest } from "next/server";
import {
- getAnalyticsEdgeQuerySchema,
analyticsEndpointSchema,
+ getAnalyticsEdgeQuerySchema,
} from "@/lib/zod/schemas/analytics";
+import { DUB_DEMO_LINKS, DUB_PROJECT_ID, getSearchParams } from "@dub/utils";
+import { NextResponse, type NextRequest } from "next/server";
export const runtime = "edge";
@@ -29,8 +29,12 @@ export const GET = async (
let link;
- // demo link (dub.sh/try)
- if (domain === "dub.sh" && key === "try") {
+ const demoLink = DUB_DEMO_LINKS.find(
+ (l) => l.domain === domain && l.key === key,
+ );
+
+ // if it's a demo link
+ if (demoLink) {
// Rate limit in production
if (process.env.NODE_ENV !== "development") {
if (await isBlacklistedReferrer(req.headers.get("referer"))) {
@@ -43,7 +47,7 @@ export const GET = async (
const { success } = await ratelimit(
15,
endpoint === "clicks" ? "10 s" : "1 h",
- ).limit(`demo-analytics:${identity_hash}:${endpoint}`);
+ ).limit(`demo-analytics:${demoLink.id}:${identity_hash}:${endpoint}`);
if (!success) {
throw new DubApiError({
@@ -53,7 +57,7 @@ export const GET = async (
}
}
link = {
- id: DEMO_LINK_ID,
+ id: demoLink.id,
projectId: DUB_PROJECT_ID,
};
} else {
diff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.ts
index 49929f8f75..76a25f17e2 100644
--- a/packages/utils/src/constants/index.ts
+++ b/packages/utils/src/constants/index.ts
@@ -59,7 +59,6 @@ export const ADMIN_HOSTNAMES = new Set([
export const DUB_LOGO = "https://assets.dub.co/logo.png";
export const DUB_THUMBNAIL = "https://assets.dub.co/thumbnail.png";
-export const DEMO_LINK_ID = "clqo10sum0006js08vutzfxt3";
export const DUB_PROJECT_ID = "cl7pj5kq4006835rbjlt2ofka";
export const LEGAL_PROJECT_ID = "clrflia0j0000vs7sqfhz9c7q";
export const LEGAL_USER_ID = "clqei1lgc0000vsnzi01pbf47";
@@ -147,3 +146,31 @@ export const DUB_DOMAINS = [
];
export const DUB_DOMAINS_ARRAY = DUB_DOMAINS.map((domain) => domain.slug);
+
+export const DUB_DEMO_LINKS = [
+ {
+ id: "clqo10sum0006js08vutzfxt3",
+ domain: "dub.sh",
+ key: "try",
+ },
+ {
+ id: "clot0z5rg000djp08ue98hxkn",
+ domain: "chatg.pt",
+ key: "domains",
+ },
+ {
+ id: "clp4jh9av0001l308ormavtlu",
+ domain: "spti.fi",
+ key: "hans",
+ },
+ {
+ id: "cltgtsex40003ck8z444hum5u",
+ domain: "git.new",
+ key: "dub",
+ },
+ {
+ id: "clp3k3yoi0001ju0874nz899q",
+ domain: "amzn.id",
+ key: "tv",
+ },
+];