Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

customDomainTerms

Steven Teyf066919d258c
diff --git a/apps/web/lib/api/domains/claim-dot-link-domain.ts b/apps/web/lib/api/domains/claim-dot-link-domain.ts
index 35fddae35c..758a07e5b9 100644
--- a/apps/web/lib/api/domains/claim-dot-link-domain.ts
+++ b/apps/web/lib/api/domains/claim-dot-link-domain.ts
@@ -11,6 +11,7 @@ import {
APP_DOMAIN_WITH_NGROK,
DEFAULT_LINK_PROPS,
} from "@dub/utils";
+import { get } from "@vercel/edge-config";
import { waitUntil } from "@vercel/functions";
import { addDomainToVercel } from "./add-domain-vercel";
import { markDomainAsDeleted } from "./mark-domain-deleted";
@@ -30,11 +31,26 @@ export async function claimDotLinkDomain({
message: "Free workspaces cannot register .link domains.",
});
- if (workspace.id !== ACME_WORKSPACE_ID) {
- if (workspace.dotLinkClaimed) {
+ if (workspace.id !== ACME_WORKSPACE_ID && workspace.dotLinkClaimed) {
+ throw new DubApiError({
+ code: "forbidden",
+ message: "Workspace is limited to one free .link domain.",
+ });
+ }
+
+ const customDomainTerms = await get("customDomainTerms");
+
+ if (customDomainTerms && Array.isArray(customDomainTerms)) {
+ const customDomainTermsRegex = new RegExp(
+ customDomainTerms
+ .map((term: string) => term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) // replace special characters with escape sequences
+ .join("|"),
+ );
+
+ if (customDomainTermsRegex.test(domain)) {
throw new DubApiError({
code: "forbidden",
- message: "Workspace is limited to one free .link domain.",
+ message: "Domain is not allowed.",
});
}
}