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.

Add Not Found support

Steven Tey2a9e0761cf1c
diff --git a/apps/web/app/[domain]/placeholder.tsx b/apps/web/app/[domain]/placeholder.tsx
index aabc4a820a..69678df760 100644
--- a/apps/web/app/[domain]/placeholder.tsx
+++ b/apps/web/app/[domain]/placeholder.tsx
@@ -74,7 +74,7 @@ export default function PlaceholderContent() {
</motion.p>
<motion.a
variants={STAGGER_CHILD_VARIANTS}
- href={createHref("/", domain, {
+ href={createHref("/home", domain, {
utm_source: "Custom Domain",
utm_medium: "Welcome Page",
utm_campaign: domain,
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index 39f7909331..5352cb7fd9 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -47,6 +47,7 @@ export const PATCH = withWorkspace(
slug: newDomain,
placeholder,
expiredUrl,
+ notFoundUrl,
archived,
} = updateDomainBodySchema.parse(await parseRequestBody(req));
@@ -88,6 +89,7 @@ export const PATCH = withWorkspace(
...(placeholder && { placeholder }),
...(workspace.plan != "free" && {
expiredUrl,
+ notFoundUrl,
}),
},
});
diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.ts
index 673766fbc5..507cf0d017 100644
--- a/apps/web/app/api/domains/route.ts
+++ b/apps/web/app/api/domains/route.ts
@@ -47,7 +47,7 @@ export const GET = withWorkspace(
export const POST = withWorkspace(
async ({ req, workspace, session }) => {
const body = await parseRequestBody(req);
- const { slug, placeholder, expiredUrl } =
+ const { slug, placeholder, expiredUrl, notFoundUrl } =
createDomainBodySchema.parse(body);
const totalDomains = await prisma.domain.count({
@@ -102,6 +102,7 @@ export const POST = withWorkspace(
...(placeholder && { placeholder }),
...(workspace.plan !== "free" && {
expiredUrl,
+ notFoundUrl,
}),
},
}),
diff --git a/apps/web/app/banned/page.tsx b/apps/web/app/banned/page.tsx
index 3df03ad137..e42f2469f2 100644
--- a/apps/web/app/banned/page.tsx
+++ b/apps/web/app/banned/page.tsx
@@ -24,7 +24,7 @@ export default async function BannedPage() {
This link has been banned for violating our terms of service.
</p>
<a
- href="https://dub.co"
+ href="https://dub.co/home"
className="rounded-full bg-gray-800 px-10 py-2 font-medium text-white transition-colors hover:bg-black"
>
Create Your Free Branded Link
diff --git a/apps/web/app/expired/[domain]/page.tsx b/apps/web/app/expired/[domain]/page.tsx
index 82449a1438..0527c9322f 100644
--- a/apps/web/app/expired/[domain]/page.tsx
+++ b/apps/web/app/expired/[domain]/page.tsx
@@ -1,7 +1,7 @@
-import { getLinkViaEdge } from "@/lib/planetscale";
+import { getDomainViaEdge } from "@/lib/planetscale/get-domain-via-edge";
import { Background, Footer, Nav, NavMobile } from "@dub/ui";
+import { CircleHalfDottedClock } from "@dub/ui/src/icons";
import { constructMetadata } from "@dub/utils";
-import { TimerOff } from "lucide-react";
import { redirect } from "next/navigation";
export const runtime = "edge";
@@ -13,12 +13,12 @@ export const metadata = constructMetadata({
noIndex: true,
});
-export default async function ExpiredPage({
+export default async function ExpiredLinkPage({
params,
}: {
params: { domain: string };
}) {
- const domain = await getLinkViaEdge(params.domain, "_root");
+ const domain = await getDomainViaEdge(params.domain);
if (domain?.expiredUrl) {
redirect(domain.expiredUrl);
@@ -29,8 +29,8 @@ export default async function ExpiredPage({
<NavMobile />
<Nav />
<div className="z-10 mx-2 my-10 flex max-w-md flex-col items-center space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-16">
- <div className="mx-auto flex h-20 w-20 items-center justify-center rounded-full border border-gray-300 bg-white/30">
- <TimerOff className="h-6 w-6 text-gray-400" />
+ <div className="mx-auto flex h-20 w-20 items-center justify-center rounded-full border border-gray-300 bg-white/80">
+ <CircleHalfDottedClock className="h-6 w-6 text-gray-400" />
</div>
<h1 className="font-display text-5xl font-bold">Expired Link</h1>
<p className="text-lg text-gray-600">
@@ -38,7 +38,7 @@ export default async function ExpiredPage({
new one.
</p>
<a
- href="https://dub.co"
+ href="https://dub.co/home"
className="rounded-full bg-gray-800 px-10 py-2 font-medium text-white transition-colors hover:bg-black"
>
Create Your Free Branded Link
diff --git a/apps/web/app/not-found/[domain]/page.tsx b/apps/web/app/not-found/[domain]/page.tsx
new file mode 100644
index 0000000000..bb8f91e5ca
--- /dev/null
+++ b/apps/web/app/not-found/[domain]/page.tsx
@@ -0,0 +1,49 @@
+import { getDomainViaEdge } from "@/lib/planetscale/get-domain-via-edge";
+import { Background, Footer, Nav, NavMobile } from "@dub/ui";
+import { constructMetadata } from "@dub/utils";
+import { redirect } from "next/navigation";
+
+export const runtime = "edge";
+
+export const metadata = constructMetadata({
+ title: "Link Not Found – Dub.co",
+ description:
+ "This link does not exist on Dub.co. Please check the URL and try again.",
+ noIndex: true,
+});
+
+export default async function NotFoundLinkPage({
+ params,
+}: {
+ params: { domain: string };
+}) {
+ const domain = await getDomainViaEdge(params.domain);
+
+ if (domain?.notFoundUrl) {
+ redirect(domain.notFoundUrl);
+ }
+
+ return (
+ <main className="flex min-h-screen flex-col justify-between">
+ <NavMobile />
+ <Nav />
+ <div className="z-10 mx-2 my-10 flex max-w-md flex-col items-center space-y-5 px-2.5 text-center sm:mx-auto sm:max-w-lg sm:px-0 lg:mb-16">
+ <div className="font-display mx-auto flex h-20 w-20 items-center justify-center rounded-full border border-gray-300 bg-white/80 text-lg font-bold text-gray-400">
+ 404
+ </div>
+ <h1 className="font-display text-5xl font-bold">Link Not Found</h1>
+ <p className="text-lg text-gray-600">
+ This link does not exist. Please check the URL and try again.
+ </p>
+ <a
+ href="https://dub.co/home"
+ className="rounded-full bg-gray-800 px-10 py-2 font-medium text-white transition-colors hover:bg-black"
+ >
+ Create Your Free Branded Link
+ </a>
+ </div>
+ <Footer />
+ <Background />
+ </main>
+ );
+}
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 52e5882d61..9ab4d7d99b 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -56,13 +56,10 @@ export default async function LinkMiddleware(
const linkData = await getLinkViaEdge(domain, key);
if (!linkData) {
- // short link not found, redirect to root
+ // short link not found, rewrite to not-found page
// TODO: log 404s (https://github.com/dubinc/dub/issues/559)
- return NextResponse.redirect(new URL("/", req.url), {
- headers: {
- ...DUB_HEADERS,
- },
- status: 302,
+ return NextResponse.rewrite(new URL(`/not-found/${domain}`, req.url), {
+ headers: DUB_HEADERS,
});
}
diff --git a/apps/web/lib/planetscale.ts b/apps/web/lib/planetscale.ts
deleted file mode 100644
index 0c7a1d7628..0000000000
--- a/apps/web/lib/planetscale.ts
+++ /dev/null
@@ -1,152 +0,0 @@
-import { nanoid, punyEncode } from "@dub/utils";
-import { connect } from "@planetscale/database";
-import { Link, Project } from "@prisma/client";
-import { WorkspaceProps } from "./types";
-
-export const DATABASE_URL =
- process.env.PLANETSCALE_DATABASE_URL || process.env.DATABASE_URL;
-
-export const pscale_config = {
- url: DATABASE_URL,
-};
-
-export const conn = connect(pscale_config);
-
-export const getWorkspaceViaEdge = async (workspaceId: string) => {
- if (!DATABASE_URL) return null;
-
- const { rows } =
- (await conn.execute<WorkspaceProps>(
- "SELECT * FROM Project WHERE id = ? LIMIT 1",
- [workspaceId.replace("ws_", "")],
- )) || {};
-
- return rows && Array.isArray(rows) && rows.length > 0 ? rows[0] : null;
-};
-
-export const checkIfKeyExists = async (domain: string, key: string) => {
- if (!DATABASE_URL) return null;
-
- const { rows } =
- (await conn.execute(
- "SELECT 1 FROM Link WHERE domain = ? AND `key` = ? LIMIT 1",
- [domain, punyEncode(decodeURIComponent(key))], // we need to make sure that the key is always URI-decoded + punycode-encoded (cause that's how we store it in MySQL)
- )) || {};
-
- return rows && Array.isArray(rows) && rows.length > 0;
-};
-
-export const checkIfUserExists = async (userId: string) => {
- if (!DATABASE_URL) return null;
-
- const { rows } =
- (await conn.execute("SELECT 1 FROM User WHERE id = ? LIMIT 1", [userId])) ||
- {};
-
- return rows && Array.isArray(rows) && rows.length > 0;
-};
-
-interface EdgeLinkProps {
- id: string;
- domain: string;
- key: string;
- url: string;
- proxy: number;
- title: string;
- description: string;
- image: string;
- video: string;
- rewrite: number;
- password: string | null;
- expiresAt: string | null;
- ios: string | null;
- android: string | null;
- geo: object | null;
- projectId: string;
- publicStats: number;
- expiredUrl: string | null;
- createdAt: string;
-}
-
-export const getLinkViaEdge = async (domain: string, key: string) => {
- if (!DATABASE_URL) return null;
-
- const { rows } =
- (await conn.execute(
- "SELECT * FROM Link WHERE domain = ? AND `key` = ?",
- [domain, punyEncode(decodeURIComponent(key))], // we need to make sure that the key is always URI-decoded + punycode-encoded (cause that's how we store it in MySQL)
- )) || {};
-
- return rows && Array.isArray(rows) && rows.length > 0
- ? (rows[0] as EdgeLinkProps)
- : null;
-};
-
-export const getShortLinkViaEdge = async (shortLink: string) => {
- if (!DATABASE_URL) return null;
-
- const { rows } =
- (await conn.execute("SELECT * FROM Link WHERE shortLink = ?", [
- shortLink,
- ])) || {};
-
- return rows && Array.isArray(rows) && rows.length > 0
- ? (rows[0] as EdgeLinkProps)
- : null;
-};
-
-export async function getRandomKey({
- domain,
- prefix,
- long,
-}: {
- domain: string;
- prefix?: string;
- long?: boolean;
-}): Promise<string> {
- /* recursively get random key till it gets one that's available */
- let key = long ? nanoid(69) : nanoid();
- if (prefix) {
- key = `${prefix.replace(/^\/|\/$/g, "")}/${key}`;
- }
- const exists = await checkIfKeyExists(domain, key);
- if (exists) {
- // by the off chance that key already exists
- return getRandomKey({ domain, prefix, long });
- } else {
- return key;
- }
-}
-
-// Get workspace by publishable key
-export const getWorkspaceByPublishableKey = async (publishableKey: string) => {
- if (!DATABASE_URL) return null;
-
- const { rows } =
- (await conn.execute(
- "SELECT * FROM Project WHERE publishableKey = ? LIMIT 1",
- [publishableKey],
- )) || {};
-
- return rows && Array.isArray(rows) && rows.length > 0
- ? (rows[0] as Project)
- : null;
-};
-
-// Get link by workspaceId and identifier
-export const getLinkByIdentifier = async (
- workspaceId: string,
- identifier: string,
-) => {
- if (!DATABASE_URL) return null;
-
- const { rows } =
- (await conn.execute(
- "SELECT * FROM Link WHERE projectId = ? AND identifier = ?",
- [workspaceId, identifier],
- )) || {};
-
- return rows && Array.isArray(rows) && rows.length > 0
- ? (rows[0] as Link)
- : null;
-};
diff --git a/apps/web/lib/planetscale/check-if-key-exists.ts b/apps/web/lib/planetscale/check-if-key-exists.ts
new file mode 100644
index 0000000000..85a1b0370c
--- /dev/null
+++ b/apps/web/lib/planetscale/check-if-key-exists.ts
@@ -0,0 +1,12 @@
+import { punyEncode } from "@dub/utils";
+import { conn } from "./connection";
+
+export const checkIfKeyExists = async (domain: string, key: string) => {
+ const { rows } =
+ (await conn.execute(
+ "SELECT 1 FROM Link WHERE domain = ? AND `key` = ? LIMIT 1",
+ [domain, punyEncode(decodeURIComponent(key))], // we need to make sure that the key is always URI-decoded + punycode-encoded (cause that's how we store it in MySQL)
+ )) || {};
+
+ return rows && Array.isArray(rows) && rows.length > 0;
+};
diff --git a/apps/web/lib/planetscale/check-if-user-exists.ts b/apps/web/lib/planetscale/check-if-user-exists.ts
new file mode 100644
index 0000000000..f9c4a25dfc
--- /dev/null
+++ b/apps/web/lib/planetscale/check-if-user-exists.ts
@@ -0,0 +1,9 @@
+import { conn } from "./connection";
+
+export const checkIfUserExists = async (userId: string) => {
+ const { rows } =
+ (await conn.execute("SELECT 1 FROM User WHERE id = ? LIMIT 1", [userId])) ||
+ {};
+
+ return rows && Array.isArray(rows) && rows.length > 0;
+};
diff --git a/apps/web/lib/planetscale/connection.ts b/apps/web/lib/planetscale/connection.ts
new file mode 100644
index 0000000000..a1daafb381
--- /dev/null
+++ b/apps/web/lib/planetscale/connection.ts
@@ -0,0 +1,5 @@
+import { connect } from "@planetscale/database";
+
+export const conn = connect({
+ url: process.env.PLANETSCALE_DATABASE_URL || process.env.DATABASE_URL,
+});
diff --git a/apps/web/lib/planetscale/get-domain-via-edge.ts b/apps/web/lib/planetscale/get-domain-via-edge.ts
new file mode 100644
index 0000000000..21220e05de
--- /dev/null
+++ b/apps/web/lib/planetscale/get-domain-via-edge.ts
@@ -0,0 +1,11 @@
+import { conn } from "./connection";
+import { EdgeDomainProps } from "./types";
+
+export const getDomainViaEdge = async (domain: string) => {
+ const { rows } =
+ (await conn.execute("SELECT * FROM Domain WHERE slug = ?", [domain])) || {};
+
+ return rows && Array.isArray(rows) && rows.length > 0
+ ? (rows[0] as EdgeDomainProps)
+ : null;
+};
diff --git a/apps/web/lib/planetscale/get-link-by-identifier.ts b/apps/web/lib/planetscale/get-link-by-identifier.ts
new file mode 100644
index 0000000000..f241af6dcd
--- /dev/null
+++ b/apps/web/lib/planetscale/get-link-by-identifier.ts
@@ -0,0 +1,18 @@
+import { Link } from "@prisma/client";
+import { conn } from "./connection";
+
+// Get link by workspaceId and identifier
+export const getLinkByIdentifier = async (
+ workspaceId: string,
+ identifier: string,
+) => {
+ const { rows } =
+ (await conn.execute(
+ "SELECT * FROM Link WHERE projectId = ? AND identifier = ?",
+ [workspaceId, identifier],
+ )) || {};
+
+ return rows && Array.isArray(rows) && rows.length > 0
+ ? (rows[0] as Link)
+ : null;
+};
diff --git a/apps/web/lib/planetscale/get-link-via-edge.ts b/apps/web/lib/planetscale/get-link-via-edge.ts
new file mode 100644
index 0000000000..88fba320f4
--- /dev/null
+++ b/apps/web/lib/planetscale/get-link-via-edge.ts
@@ -0,0 +1,15 @@
+import { punyEncode } from "@dub/utils";
+import { conn } from "./connection";
+import { EdgeLinkProps } from "./types";
+
+export const getLinkViaEdge = async (domain: string, key: string) => {
+ const { rows } =
+ (await conn.execute(
+ "SELECT * FROM Link WHERE domain = ? AND `key` = ?",
+ [domain, punyEncode(decodeURIComponent(key))], // we need to make sure that the key is always URI-decoded + punycode-encoded (cause that's how we store it in MySQL)
+ )) || {};
+
+ return rows && Array.isArray(rows) && rows.length > 0
+ ? (rows[0] as EdgeLinkProps)
+ : null;
+};
diff --git a/apps/web/lib/planetscale/get-random-key.ts b/apps/web/lib/planetscale/get-random-key.ts
new file mode 100644
index 0000000000..31b84d8ab9
--- /dev/null
+++ b/apps/web/lib/planetscale/get-random-key.ts
@@ -0,0 +1,25 @@
+import { nanoid } from "@dub/utils";
+import { checkIfKeyExists } from "./check-if-key-exists";
+
+export async function getRandomKey({
+ domain,
+ prefix,
+ long,
+}: {
+ domain: string;
+ prefix?: string;
+ long?: boolean;
+}): Promise<string> {
+ /* recursively get random key till it gets one that's available */
+ let key = long ? nanoid(69) : nanoid();
+ if (prefix) {
+ key = `${prefix.replace(/^\/|\/$/g, "")}/${key}`;
+ }
+ const exists = await checkIfKeyExists(domain, key);
+ if (exists) {
+ // by the off chance that key already exists
+ return getRandomKey({ domain, prefix, long });
+ } else {
+ return key;
+ }
+}
diff --git a/apps/web/lib/planetscale/get-shortlink-via-edge.ts b/apps/web/lib/planetscale/get-shortlink-via-edge.ts
new file mode 100644
index 0000000000..870326dca6
--- /dev/null
+++ b/apps/web/lib/planetscale/get-shortlink-via-edge.ts
@@ -0,0 +1,13 @@
+import { conn } from "./connection";
+import { EdgeLinkProps } from "./types";
+
+export const getShortLinkViaEdge = async (shortLink: string) => {
+ const { rows } =
+ (await conn.execute("SELECT * FROM Link WHERE shortLink = ?", [
+ shortLink,
+ ])) || {};
+
+ return rows && Array.isArray(rows) && rows.length > 0
+ ? (rows[0] as EdgeLinkProps)
+ : null;
+};
diff --git a/apps/web/lib/planetscale/get-workspace-by-publishable-key.ts b/apps/web/lib/planetscale/get-workspace-by-publishable-key.ts
new file mode 100644
index 0000000000..1c64ac9595
--- /dev/null
+++ b/apps/web/lib/planetscale/get-workspace-by-publishable-key.ts
@@ -0,0 +1,15 @@
+import { Project } from "@prisma/client";
+import { conn } from "./connection";
+
+// Get workspace by publishable key
+export const getWorkspaceByPublishableKey = async (publishableKey: string) => {
+ const { rows } =
+ (await conn.execute(
+ "SELECT * FROM Project WHERE publishableKey = ? LIMIT 1",
+ [publishableKey],
+ )) || {};
+
+ return rows && Array.isArray(rows) && rows.length > 0
+ ? (rows[0] as Project)
+ : null;
+};
diff --git a/apps/web/lib/planetscale/get-workspace-via-edge.ts b/apps/web/lib/planetscale/get-workspace-via-edge.ts
new file mode 100644
index 0000000000..70814f97d8
--- /dev/null
+++ b/apps/web/lib/planetscale/get-workspace-via-edge.ts
@@ -0,0 +1,12 @@
+import { WorkspaceProps } from "../types";
+import { conn } from "./connection";
+
+export const getWorkspaceViaEdge = async (workspaceId: string) => {
+ const { rows } =
+ (await conn.execute<WorkspaceProps>(
+ "SELECT * FROM Project WHERE id = ? LIMIT 1",
+ [workspaceId.replace("ws_", "")],
+ )) || {};
+
+ return rows && Array.isArray(rows) && rows.length > 0 ? rows[0] : null;
+};
diff --git a/apps/web/lib/planetscale/index.ts b/apps/web/lib/planetscale/index.ts
new file mode 100644
index 0000000000..06172b1f90
--- /dev/null
+++ b/apps/web/lib/planetscale/index.ts
@@ -0,0 +1,10 @@
+export * from "./check-if-key-exists";
+export * from "./check-if-user-exists";
+export * from "./connection";
+export * from "./get-link-by-identifier";
+export * from "./get-link-via-edge";
+export * from "./get-random-key";
+export * from "./get-shortlink-via-edge";
+export * from "./get-workspace-by-publishable-key";
+export * from "./get-workspace-via-edge";
+export * from "./types";
diff --git a/apps/web/lib/planetscale/types.ts b/apps/web/lib/planetscale/types.ts
new file mode 100644
index 0000000000..d4d8de9b62
--- /dev/null
+++ b/apps/web/lib/planetscale/types.ts
@@ -0,0 +1,36 @@
+export interface EdgeLinkProps {
+ id: string;
+ domain: string;
+ key: string;
+ url: string;
+ proxy: number;
+ title: string;
+ description: string;
+ image: string;
+ video: string;
+ rewrite: number;
+ password: string | null;
+ expiresAt: string | null;
+ ios: string | null;
+ android: string | null;
+ geo: object | null;
+ projectId: string;
+ publicStats: number;
+ expiredUrl: string | null;
+ createdAt: string;
+}
+
+export interface EdgeDomainProps {
+ id: string;
+ slug: string;
+ verified: number;
+ placeholder: string;
+ expiredUrl: string | null;
+ notFoundUrl: string | null;
+ primary: number;
+ archived: number;
+ projectId: string;
+ lastChecked: string;
+ createdAt: string;
+ updatedAt: string;
+}
diff --git a/apps/web/lib/swr/use-default-domains.ts b/apps/web/lib/swr/use-default-domains.ts
index d289c3f826..32f8a91c2b 100644
--- a/apps/web/lib/swr/use-default-domains.ts
+++ b/apps/web/lib/swr/use-default-domains.ts
@@ -26,8 +26,6 @@ export default function useDefaultDomains({
: data;
}, [data, flags]);
- console.log({ defaultDomains });
-
return {
defaultDomains,
loading: !data && !error,
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 4431bc920d..6172d5c9c2 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -120,6 +120,7 @@ export interface DomainProps {
archived: boolean;
placeholder?: string;
expiredUrl?: string;
+ notFoundUrl?: string;
projectId: string;
registeredDomain?: RegisteredDomainProps;
}
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index 37d8c8b080..f42471dfff 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -34,6 +34,13 @@ export const DomainSchema = z.object({
"The URL to redirect to when a link under this domain has expired.",
)
.openapi({ example: "https://acme.com/expired" }),
+ notFoundUrl: z
+ .string()
+ .nullable()
+ .describe(
+ "The URL to redirect to when a link under this domain doesn't exist.",
+ )
+ .openapi({ example: "https://acme.com/not-found" }),
createdAt: z.date().describe("The date the domain was created."),
updatedAt: z.date().describe("The date the domain was last updated."),
registeredDomain: z
@@ -84,6 +91,12 @@ export const createDomainBodySchema = z.object({
"Redirect users to a specific URL when any link under this domain has expired.",
)
.openapi({ example: "https://acme.com/expired" }),
+ notFoundUrl: parseUrlSchemaAllowEmpty
+ .nullish()
+ .describe(
+ "Redirect users to a specific URL when a link under this domain doesn't exist.",
+ )
+ .openapi({ example: "https://acme.com/not-found" }),
archived: z
.boolean()
.optional()
diff --git a/apps/web/prisma/schema/domain.prisma b/apps/web/prisma/schema/domain.prisma
index 5d4ceb906e..bb5f1a610f 100644
--- a/apps/web/prisma/schema/domain.prisma
+++ b/apps/web/prisma/schema/domain.prisma
@@ -4,6 +4,7 @@ model Domain {
verified Boolean @default(false)
placeholder String @default("https://dub.co/help/article/what-is-dub")
expiredUrl String? @db.LongText // URL to redirect to for expired links
+ notFoundUrl String? @db.LongText // URL to redirect to for links that don't exist
primary Boolean @default(false)
archived Boolean @default(false)
lastChecked DateTime @default(now())
diff --git a/apps/web/ui/domains/add-edit-domain-form.tsx b/apps/web/ui/domains/add-edit-domain-form.tsx
index afaad271d4..93b2d314a7 100644
--- a/apps/web/ui/domains/add-edit-domain-form.tsx
+++ b/apps/web/ui/domains/add-edit-domain-form.tsx
@@ -44,7 +44,9 @@ export function AddEditDomainForm({
},
);
- const { slug: domain, placeholder, expiredUrl } = data;
+ console.log({ props, data });
+
+ const { slug: domain, placeholder, expiredUrl, notFoundUrl } = data;
const [lockDomain, setLockDomain] = useState(true);
const [saving, setSaving] = useState(false);
@@ -88,6 +90,8 @@ export function AddEditDomainForm({
const [showDefaultExpirationUrl, setShowDefaultExpirationUrl] = useState(
!!data.expiredUrl,
);
+ const [showNotFoundUrl, setShowNotFoundUrl] = useState(!!data.notFoundUrl);
+
const [showPlaceholderUrl, setShowPlaceholderUrl] = useState(
!!data.placeholder,
);
@@ -240,6 +244,51 @@ export function AddEditDomainForm({
</motion.div>
</div>
+ <div>
+ <label className="flex items-center justify-between gap-2">
+ <div className="flex items-center gap-2">
+ <h2 className="text-sm font-medium text-gray-900">
+ Not Found URL
+ </h2>
+ <ProBadgeTooltip
+ content={
+ <SimpleTooltipContent
+ title="Redirect users to a specific URL when a link under this domain doesn't exist."
+ cta="Learn more."
+ href="https://dub.co/help/article/not-found-url"
+ />
+ }
+ />
+ </div>
+ <Switch
+ checked={showNotFoundUrl}
+ fn={(checked) => {
+ setShowNotFoundUrl(checked);
+ if (!checked) setData((d) => ({ ...d, notFoundUrl: "" }));
+ }}
+ />
+ </label>
+ <motion.div
+ animate={{ height: showNotFoundUrl ? "auto" : 0 }}
+ transition={{ duration: 0.1 }}
+ initial={false}
+ className="-m-1 overflow-hidden p-1"
+ >
+ <div className="relative mt-2 rounded-md shadow-sm">
+ <input
+ name="notFoundUrl"
+ id="notFoundUrl"
+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
+ placeholder="https://yourwebsite.com"
+ value={notFoundUrl}
+ onChange={(e) =>
+ setData((d) => ({ ...d, notFoundUrl: e.target.value }))
+ }
+ />
+ </div>
+ </motion.div>
+ </div>
+
<div>
<label className="flex items-center justify-between gap-2">
<div className="flex items-center gap-2">