The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Merge branch 'main' into feat/utm-tracking
Snazzah21ae78c532e2
diff --cc lib/middleware/link.tsindex 321f38d5d0,c200a7b66a..8d87bc302e--- a/lib/middleware/link.ts+++ b/lib/middleware/link.ts@@@ -21,35 -21,22 +21,22 @@@ export default async function LinkMiddlreturn NextResponse.next();}- const ip = req.ip ?? "127.0.0.1";- const { success, limit, reset, remaining } = await ratelimit.limit(- `dub_${ip}`+ const response = await redis.hget<Omit<LinkProps, "key">>(+ `${hostname}:links`,+ key);+ const { url: target, description, image } = response || {};- let res;+ if (target) {+ const isBot = detectBot(req);- if (success) {- // if ratelimit is not exceeded- const response = await redis.hget<Omit<LinkProps, "key">>(- `${hostname}:links`,- key- );- const { url: target, description, image } = response || {};- ev.waitUntil(recordClick(hostname, req, key)); // increment click count++ ev.waitUntil(recordClick(hostname, req, query, key)); // increment click count- if (target) {- const isBot = detectBot(req);-- ev.waitUntil(recordClick(hostname, req, query, key)); // increment click count-- if (image && description && isBot) {- // rewrite to proxy page (dub.sh/proxy/[domain]/[key])- res = NextResponse.rewrite(`https://dub.sh/proxy/${hostname}/${key}`);- } else {- res = NextResponse.redirect(target);- }+ if (image && description && isBot) {+ // rewrite to proxy page (dub.sh/proxy/[domain]/[key])+ return NextResponse.rewrite(`https://dub.sh/proxy/${hostname}/${key}`);} else {- url.pathname = "/";- res = NextResponse.redirect(url);+ return NextResponse.redirect(target);}} else {url.pathname = "/";