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.

change root clicks behavior for dub.sh

Steven Teyc911755a1794
diff --git a/lib/middleware/root.ts b/lib/middleware/root.ts
index e0030d3c18..347a79c607 100644
--- a/lib/middleware/root.ts
+++ b/lib/middleware/root.ts
@@ -1,5 +1,5 @@
import { NextRequest, NextFetchEvent, NextResponse } from "next/server";
-import { recordClick } from "@/lib/upstash";
+import { recordClick, redis } from "@/lib/upstash";
import { parse } from "./utils";
export default function RootMiddleware(req: NextRequest, ev: NextFetchEvent) {
@@ -9,8 +9,14 @@ export default function RootMiddleware(req: NextRequest, ev: NextFetchEvent) {
return NextResponse.next();
}
- if (hostname !== "preview.dub.sh" && !hostname.endsWith(".vercel.app")) {
- ev.waitUntil(recordClick(hostname, req)); // record clicks on root page (if it's not a Vercel preview link)
+ if (
+ hostname === "dub.sh" ||
+ hostname === "preview.dub.sh" ||
+ hostname.endsWith(".vercel.app")
+ ) {
+ ev.waitUntil(redis.incr("dub.sh:root:clicks")); // increment root clicks (only for dub.sh)
+ } else {
+ ev.waitUntil(recordClick(hostname, req)); // record clicks on root page (if hostname is not dub.sh)
}
if (