The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
lowercase domain, add _createNotFoundCacheKeys to crawl fn
Steven Tey388e1afcbf86
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.tsindex 64eeb38185..a4742e37fe 100644--- a/apps/web/app/api/domains/[domain]/route.ts+++ b/apps/web/app/api/domains/[domain]/route.ts@@ -207,7 +207,7 @@ export const PATCH = withWorkspace((notFoundUrl !== undefined && notFoundUrl !== oldNotFoundUrl) ||(expiredUrl !== undefined && expiredUrl !== oldExpiredUrl)) {- revalidateTag(`notfound:${domain}`);+ revalidateTag(`notfound:${domain.toLowerCase()}`);}if (domainUpdated) {diff --git a/apps/web/lib/api/links/cache.ts b/apps/web/lib/api/links/cache.tsindex 9ecce2b06e..4506792107 100644--- a/apps/web/lib/api/links/cache.ts+++ b/apps/web/lib/api/links/cache.ts@@ -41,7 +41,7 @@ class LinkCache {const redisLink = formatRedisLink(link);const cacheKey = this._createKey({ domain: link.domain, key: link.key });pipeline.set(cacheKey, redisLink, { ex: REDIS_CACHE_EXPIRATION });- revalidateTag(`notfound:${link.domain}:${link.key}`);+ revalidateTag(`notfound:${link.domain.toLowerCase()}:${link.key}`);});return await pipeline.exec();@@ -53,7 +53,7 @@ class LinkCache {// Update LRU cache immediately to prevent stale readslinkLRUCache.set(cacheKey, redisLink);- revalidateTag(`notfound:${link.domain}:${link.key}`);+ revalidateTag(`notfound:${link.domain.toLowerCase()}:${link.key}`);await Promise.all([redisGlobal.set(cacheKey, redisLink, {@@ -171,6 +171,7 @@ class LinkCache {}_createNotFoundCacheKeys({ domain, key }: Pick<LinkProps, "domain" | "key">) {+ domain = domain.toLowerCase();// here we set 2 cache tags to invalidate the cache:// 1. notfound:${domain}:${key} - for the specific not found link// 2. notfound:${domain} - scope all links under the domain (for easy purging in PATCH /domains/:domain)diff --git a/apps/web/lib/middleware/utils/crawl-bitly.ts b/apps/web/lib/middleware/utils/crawl-bitly.tsindex f5e13d206d..f687f7ca07 100644--- a/apps/web/lib/middleware/utils/crawl-bitly.ts+++ b/apps/web/lib/middleware/utils/crawl-bitly.ts@@ -1,3 +1,4 @@+import { linkCache } from "@/lib/api/links/cache";import { redis } from "@/lib/upstash";import { DUB_HEADERS } from "@dub/utils";import { NextRequest, NextResponse } from "next/server";@@ -21,7 +22,14 @@ export const crawlBitly = async (req: NextRequest) => {}return NextResponse.redirect("https://buffer.com", {- headers: DUB_HEADERS,+ headers: {+ ...DUB_HEADERS,+ "Vercel-CDN-Cache-Control": "public, s-maxage=86400",+ "Vercel-Cache-Tag": linkCache._createNotFoundCacheKeys({+ domain,+ key: fullKey,+ }),+ },status: 302,});};