The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix default domain implementation
Steven Tey4a5a0e54f858
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.tsindex a3d240b01f..ec7837d212 100644--- a/apps/web/lib/api/links/process-link.ts+++ b/apps/web/lib/api/links/process-link.ts@@ -182,11 +182,11 @@ export async function processLink<T extends Record<string, any>>({} else if (isDubDomain(domain)) {// coerce type with ! cause we already checked if it existsconst { allowedHostnames } = DUB_DOMAINS.find((d) => d.slug === domain)!;- const urlDomain = getDomainWithoutWWW(url) || "";+ const urlDomain = getApexDomain(url) || "";if (allowedHostnames && !allowedHostnames.includes(urlDomain)) {return {link: payload,- error: `Invalid URL. You can only use ${domain} short links for URLs starting with ${allowedHostnames+ error: `Invalid destination URL. You can only create ${domain} short links for URLs with the domain${allowedHostnames.length > 1 ? "s" : ""} ${allowedHostnames.map((d) => `"${d}"`).join(", ")}.`,code: "unprocessable_entity",diff --git a/apps/web/tests/links/bulk-update-link.test.ts b/apps/web/tests/links/bulk-update-link.test.tsindex 00e4b9a33c..0123723397 100644--- a/apps/web/tests/links/bulk-update-link.test.ts+++ b/apps/web/tests/links/bulk-update-link.test.ts@@ -89,7 +89,7 @@ test("PATCH /links/bulk", async (ctx) => {// third link will throw an error because git.new only allows certain destination URLsexpect(links[2]).toStrictEqual({- error: `Invalid URL. You can only use git.new short links for URLs starting with "github.com", "gist.github.com".`,+ error: `Invalid destination URL. You can only create git.new short links for URLs with the domain "github.com".`,code: "unprocessable_entity",link: expect.any(Object),});diff --git a/packages/utils/src/constants/dub-domains.ts b/packages/utils/src/constants/dub-domains.tsindex 7aaad15fca..dd604f2a96 100644--- a/packages/utils/src/constants/dub-domains.ts+++ b/packages/utils/src/constants/dub-domains.ts@@ -33,7 +33,7 @@ export const DUB_DOMAINS = [primary: false,archived: false,placeholder: "https://chat.openai.com/g/g-UGjKKONEe-domainsgpt",- allowedHostnames: ["chat.openai.com", "chatgpt.com"],+ allowedHostnames: ["openai.com", "chatgpt.com"],description:"Branded domain for ChatGPT links (convos, custom GPTs).",projectId: DUB_WORKSPACE_ID,@@ -45,7 +45,7 @@ export const DUB_DOMAINS = [primary: false,archived: false,placeholder: "https://open.spotify.com/album/1SCyi9a5pOasikidToUY5y",- allowedHostnames: ["open.spotify.com"],+ allowedHostnames: ["spotify.com"],description:"Branded domain for Spotify links (songs, playlists, etc.).",projectId: DUB_WORKSPACE_ID,@@ -57,7 +57,7 @@ export const DUB_DOMAINS = [primary: false,archived: false,placeholder: "https://github.com/dubinc/dub",- allowedHostnames: ["github.com", "gist.github.com"],+ allowedHostnames: ["github.com"],description:"Branded domain for GitHub links (repositories, gists, etc.).",projectId: DUB_WORKSPACE_ID,@@ -95,16 +95,7 @@ export const DUB_DOMAINS = ["google.ca","google.es","google.fr",- "docs.google.com",- "drive.google.com",- "calendar.google.com",- "maps.google.com",- "photos.google.com",- "search.google.com","googleblog.com",- "developers.googleblog.com",- "chromewebstore.google.com",- "play.google.com","blog.google","g.page","youtube.com",diff --git a/packages/utils/src/functions/domains.ts b/packages/utils/src/functions/domains.tsindex a4d35e82f4..ef564b5555 100644--- a/packages/utils/src/functions/domains.ts+++ b/packages/utils/src/functions/domains.ts@@ -55,8 +55,6 @@ export const getApexDomain = (url: string) => {return "";}if (domain === "youtu.be") return "youtube.com";- if (domain === "raw.githubusercontent.com") return "github.com";- if (domain.endsWith(".vercel.app")) return "vercel.app";const parts = domain.split(".");if (parts.length > 2) {