From 2a9e0761cf1c0d0e9ad46bda9b99edd4295bc2ac Mon Sep 17 00:00:00 2001 From: Steven Tey Date: Sat, 12 Oct 2024 18:12:23 -0700 Subject: [PATCH 1/4] Add Not Found support --- apps/web/app/[domain]/placeholder.tsx | 2 +- apps/web/app/api/domains/[domain]/route.ts | 2 + apps/web/app/api/domains/route.ts | 3 +- apps/web/app/banned/page.tsx | 2 +- apps/web/app/expired/[domain]/page.tsx | 14 +- apps/web/app/not-found/[domain]/page.tsx | 49 ++++++ apps/web/lib/middleware/link.ts | 9 +- apps/web/lib/planetscale.ts | 152 ------------------ .../lib/planetscale/check-if-key-exists.ts | 12 ++ .../lib/planetscale/check-if-user-exists.ts | 9 ++ apps/web/lib/planetscale/connection.ts | 5 + .../lib/planetscale/get-domain-via-edge.ts | 11 ++ .../lib/planetscale/get-link-by-identifier.ts | 18 +++ apps/web/lib/planetscale/get-link-via-edge.ts | 15 ++ apps/web/lib/planetscale/get-random-key.ts | 25 +++ .../lib/planetscale/get-shortlink-via-edge.ts | 13 ++ .../get-workspace-by-publishable-key.ts | 15 ++ .../lib/planetscale/get-workspace-via-edge.ts | 12 ++ apps/web/lib/planetscale/index.ts | 10 ++ apps/web/lib/planetscale/types.ts | 36 +++++ apps/web/lib/swr/use-default-domains.ts | 2 - apps/web/lib/types.ts | 1 + apps/web/lib/zod/schemas/domains.ts | 13 ++ apps/web/prisma/schema/domain.prisma | 1 + apps/web/ui/domains/add-edit-domain-form.tsx | 51 +++++- 25 files changed, 311 insertions(+), 171 deletions(-) create mode 100644 apps/web/app/not-found/[domain]/page.tsx delete mode 100644 apps/web/lib/planetscale.ts create mode 100644 apps/web/lib/planetscale/check-if-key-exists.ts create mode 100644 apps/web/lib/planetscale/check-if-user-exists.ts create mode 100644 apps/web/lib/planetscale/connection.ts create mode 100644 apps/web/lib/planetscale/get-domain-via-edge.ts create mode 100644 apps/web/lib/planetscale/get-link-by-identifier.ts create mode 100644 apps/web/lib/planetscale/get-link-via-edge.ts create mode 100644 apps/web/lib/planetscale/get-random-key.ts create mode 100644 apps/web/lib/planetscale/get-shortlink-via-edge.ts create mode 100644 apps/web/lib/planetscale/get-workspace-by-publishable-key.ts create mode 100644 apps/web/lib/planetscale/get-workspace-via-edge.ts create mode 100644 apps/web/lib/planetscale/index.ts create mode 100644 apps/web/lib/planetscale/types.ts 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() { { 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.

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({