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.

change file convention from "+auth" to "protected" and simplify custom domain stats pages

Steven Teyb85fe275bd11
diff --git a/app/[domain]/stats/[key]/page.tsx b/app/[domain]/stats/[key]/page.tsx
index 0c3c5f6ef8..93b9aa6500 100644
--- a/app/[domain]/stats/[key]/page.tsx
+++ b/app/[domain]/stats/[key]/page.tsx
@@ -1,69 +1,27 @@
-import prisma from "#/lib/prisma";
import { notFound } from "next/navigation";
import Stats from "#/ui/stats";
import { Suspense } from "react";
+import { getLinkViaEdge } from "#/lib/planetscale";
+import { constructMetadata } from "#/lib/utils";
+
+export const runtime = "edge";
export async function generateMetadata({
params,
}: {
params: { domain: string; key: string };
}) {
- const data = await prisma.link.findUnique({
- where: {
- domain_key: {
- domain: params.domain,
- key: params.key,
- },
- },
- select: {
- publicStats: true,
- url: true,
- },
- });
+ const data = await getLinkViaEdge(params.domain, params.key);
if (!data || !data.publicStats) {
return;
}
- const title = `Stats for ${params.domain}/${params.key} - Dub`;
- const description = `Stats page for ${params.domain}/${params.key}, which redirects to ${data.url}.`;
- const image = `https://${params.domain}/api/og/stats?domain=${params.domain}&key=${params.key}`;
-
- return {
- title,
- description,
- image,
- twitter: {
- card: "summary_large_image",
- title,
- description,
- image,
- creator: "@dubdotsh",
- },
- };
-}
-
-export async function generateStaticParams() {
- const links =
- process.env.VERCEL_ENV === "production"
- ? await prisma.link.findMany({
- where: {
- publicStats: true,
- NOT: {
- id: "cl9knuml512583yhrbjk0k55yl", // omit `dub.sh/github` since it's already statically generated
- },
- },
- select: {
- domain: true,
- key: true,
- },
- })
- : [];
-
- return links.map(({ domain, key }) => ({
- domain,
- key,
- }));
+ return constructMetadata({
+ title: `Stats for ${params.domain}/${params.key} - Dub`,
+ description: `Stats page for ${params.domain}/${params.key}, which redirects to ${data.url}.`,
+ image: `https://${params.domain}/api/og/stats?domain=${params.domain}&key=${params.key}`,
+ });
}
export default async function StatsPage({
@@ -71,17 +29,7 @@ export default async function StatsPage({
}: {
params: { domain: string; key: string };
}) {
- const data = await prisma.link.findUnique({
- where: {
- domain_key: {
- domain: params.domain,
- key: params.key,
- },
- },
- select: {
- publicStats: true,
- },
- });
+ const data = await getLinkViaEdge(params.domain, params.key);
if (!data || !data.publicStats) {
notFound();
diff --git a/app/+auth/[domain]/[key]/action.ts b/app/protected/[domain]/[key]/action.ts
similarity index 100%
rename from app/+auth/[domain]/[key]/action.ts
rename to app/protected/[domain]/[key]/action.ts
diff --git a/app/+auth/[domain]/[key]/form.tsx b/app/protected/[domain]/[key]/form.tsx
similarity index 98%
rename from app/+auth/[domain]/[key]/form.tsx
rename to app/protected/[domain]/[key]/form.tsx
index 21903222a4..7d331f2568 100644
--- a/app/+auth/[domain]/[key]/form.tsx
+++ b/app/protected/[domain]/[key]/form.tsx
@@ -8,6 +8,8 @@ import { AlertCircleFill } from "@/components/shared/icons";
import Button from "#/ui/button";
import { toast } from "sonner";
+export const runtime = "edge";
+
export default function PasswordForm() {
const { domain, key } = useParams() as {
domain: string;
diff --git a/app/+auth/[domain]/[key]/page.tsx b/app/protected/[domain]/[key]/page.tsx
similarity index 100%
rename from app/+auth/[domain]/[key]/page.tsx
rename to app/protected/[domain]/[key]/page.tsx
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index bc1a73509e..58b017678f 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -35,8 +35,10 @@ export default async function LinkMiddleware(
}
if (password) {
- // rewrite to auth page (/+auth/[domain]/[key]) if the link is password protected
- return NextResponse.rewrite(new URL(`/+auth/${domain}/${key}`, req.url));
+ // rewrite to auth page (/protected/[domain]/[key]) if the link is password protected
+ return NextResponse.rewrite(
+ new URL(`/protected/${domain}/${key}`, req.url),
+ );
}
const isBot = detectBot(req);