The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix apex domain bug
Steven Tey45a2312d6816
diff --git a/lib/constants/index.ts b/lib/constants/index.tsindex 9364249681..8bb8effed9 100644--- a/lib/constants/index.ts+++ b/lib/constants/index.ts@@ -96,9 +96,17 @@ export const SECOND_LEVEL_DOMAINS = new Set(["in",]);-export const SPECIAL_APEX_DOMAINS = {- "youtu.be": "youtube.com",-};+export const SPECIAL_APEX_DOMAINS = new Set([+ "my.id",+ "github.io",+ "vercel.app",+ "now.sh",+ "pages.dev",+ "webflow.io",+ "netlify.app",+ "fly.dev",+ "web.app",+]);export const DEFAULT_LINK_PROPS = {key: "github",diff --git a/lib/utils.ts b/lib/utils.tsindex a0df0273d6..8bc3bedf13 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -243,15 +243,16 @@ export const getApexDomain = (url: string) => {} catch (e) {return "";}- // special apex domains (e.g. youtu.be)- if (SPECIAL_APEX_DOMAINS[domain]) return SPECIAL_APEX_DOMAINS[domain];+ if (domain === "youtu.be") return "youtube.com";const parts = domain.split(".");if (parts.length > 2) {- // if this is a second-level TLD (e.g. co.uk, .com.ua, .org.tt), we need to return the last 3 partsif (- SECOND_LEVEL_DOMAINS.has(parts[parts.length - 2]) &&- ccTLDs.has(parts[parts.length - 1])+ // if this is a second-level TLD (e.g. co.uk, .com.ua, .org.tt), we need to return the last 3 parts+ (SECOND_LEVEL_DOMAINS.has(parts[parts.length - 2]) &&+ ccTLDs.has(parts[parts.length - 1])) ||+ // if it's a special subdomain for website builders (e.g. weathergpt.vercel.app/)+ SPECIAL_APEX_DOMAINS.has(parts.slice(-2).join("."))) {return parts.slice(-3).join(".");}diff --git a/pages/api/links/[key]/index.ts b/pages/api/links/[key]/index.tsindex 183be3c165..1693391c11 100644--- a/pages/api/links/[key]/index.ts+++ b/pages/api/links/[key]/index.ts@@ -1,7 +1,7 @@import { withLinksAuth } from "#/lib/auth";import { deleteLink, editLink, processKey } from "#/lib/api/links";import { isBlacklistedDomain, isBlacklistedKey } from "#/lib/edge-config";-import { log } from "#/lib/utils";+import { getApexDomain, log } from "#/lib/utils";import { GOOGLE_FAVICON_URL } from "#/lib/constants";export const config = {@@ -63,7 +63,11 @@ export default withLinksAuth(},),...(!project- ? [fetch(`${GOOGLE_FAVICON_URL}${url}`).then((res) => !res.ok)]+ ? [+ fetch(`${GOOGLE_FAVICON_URL}${getApexDomain(url)}`).then(+ (res) => !res.ok,+ ),+ ]: []),// @ts-ignore]).then((results) => results.map((result) => result.value));diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex d7df4a1203..b518967b55 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -1,7 +1,7 @@import { addLink, getLinksForProject, processKey } from "#/lib/api/links";import { withLinksAuth } from "#/lib/auth";import { isBlacklistedDomain, isBlacklistedKey } from "#/lib/edge-config";-import { log } from "#/lib/utils";+import { getApexDomain, log } from "#/lib/utils";import { DUB_PROJECT_ID, GOOGLE_FAVICON_URL } from "#/lib/constants";export const config = {@@ -72,7 +72,11 @@ export default withLinksAuth(userId: session.user.id,}),...(!project- ? [fetch(`${GOOGLE_FAVICON_URL}${url}`).then((res) => !res.ok)]+ ? [+ fetch(`${GOOGLE_FAVICON_URL}${getApexDomain(url)}`).then(+ (res) => !res.ok,+ ),+ ]: []),// @ts-ignore]).then((results) => results.map((result) => result.value));