The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
make sure Dub created buff.ly links are supported during the conversion period
Steven Tey385e0bedf8f5
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.tsindex f64257cd30..97df91b664 100644--- a/apps/web/lib/middleware/link.ts+++ b/apps/web/lib/middleware/link.ts@@ -83,11 +83,21 @@ export default async function LinkMiddleware(});if (!linkData) {- // special case for buff.ly+ // TODO: remove this once everything is migrated over and are case-sensitive+ // don't forget to remove ignoreCaseSensitivity too, it won't be needed anymoreif (domain === "buff.ly") {- return NextResponse.redirect(- new URL(`/api/links/crawl/bitly/${domain}/${key}`, req.url),- );+ // double check if the regular version exists+ linkData = await getLinkViaEdge({+ domain,+ key,+ ignoreCaseSensitivity: true,+ });++ if (!linkData) {+ return NextResponse.redirect(+ new URL(`/api/links/crawl/bitly/${domain}/${key}`, req.url),+ );+ }}if (!linkData) {diff --git a/apps/web/lib/planetscale/get-link-via-edge.ts b/apps/web/lib/planetscale/get-link-via-edge.tsindex 3c04dada4a..c9d365e610 100644--- a/apps/web/lib/planetscale/get-link-via-edge.ts+++ b/apps/web/lib/planetscale/get-link-via-edge.ts@@ -10,17 +10,20 @@ import { EdgeLinkProps } from "./types";export const getLinkViaEdge = async ({domain,key,+ ignoreCaseSensitivity = false,}: {domain: string;key: string;+ ignoreCaseSensitivity?: boolean;}) => {const isCaseSensitive = isCaseSensitiveDomain(domain);- const keyToQuery = isCaseSensitive- ? // for case sensitive domains, we need to encode the key- encodeKey(key)- : // for non-case sensitive domains, we need to make sure that the key is always URI-decoded + punycode-encoded- // (cause that's how we store it in MySQL)- punyEncode(decodeURIComponent(key));+ const keyToQuery =+ isCaseSensitive && !ignoreCaseSensitivity+ ? // for case sensitive domains, we need to encode the key+ encodeKey(key)+ : // for non-case sensitive domains, we need to make sure that the key is always URI-decoded + punycode-encoded+ // (cause that's how we store it in MySQL)+ punyEncode(decodeURIComponent(key));const { rows } =(await conn.execute("SELECT * FROM Link WHERE domain = ? AND `key` = ?", [