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.

move expiredUrl to domain level

Steven Tey691c3ae487fe
diff --git a/apps/web/app/expired/[workspaceId]/page.tsx b/apps/web/app/expired/[domain]/page.tsx
similarity index 86%
rename from apps/web/app/expired/[workspaceId]/page.tsx
rename to apps/web/app/expired/[domain]/page.tsx
index 05780a90f8..70e2fc8b31 100644
--- a/apps/web/app/expired/[workspaceId]/page.tsx
+++ b/apps/web/app/expired/[domain]/page.tsx
@@ -1,4 +1,4 @@
-import { getWorkspaceViaEdge } from "@/lib/planetscale";
+import { getDomainViaEdge, getWorkspaceViaEdge } from "@/lib/planetscale";
import { Background, Footer, Nav } from "@dub/ui";
import { constructMetadata } from "@dub/utils";
import { TimerOff } from "lucide-react";
@@ -16,12 +16,12 @@ export const metadata = constructMetadata({
export default async function ExpiredPage({
params,
}: {
- params: { workspaceId: string };
+ params: { domain: string };
}) {
- const workspace = await getWorkspaceViaEdge(params.workspaceId);
+ const domain = await getDomainViaEdge(params.domain);
- if (workspace?.slug === "acme") {
- redirect("https://dub.co");
+ if (domain?.expiredUrl) {
+ redirect(domain.expiredUrl);
}
return (
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 037732e66c..827eb695e8 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -125,7 +125,7 @@ export default async function LinkMiddleware(
return NextResponse.redirect(expiredUrl, DUB_HEADERS);
} else {
return NextResponse.rewrite(
- new URL(`/expired/${link.projectId}`, req.url),
+ new URL(`/expired/${domain}`, req.url),
DUB_HEADERS,
);
}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index f1eb32b6c2..2ba0b91d38 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -127,6 +127,7 @@ export interface DomainProps {
placeholder?: string;
clicks: number;
projectId: string;
+ expiredUrl?: string;
}
export interface RedisDomainProps {
id: string;
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 3cd3efa5fa..6af079285c 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -100,7 +100,6 @@ model Project {
domainsLimit Int @default(3)
tagsLimit Int @default(5)
usersLimit Int @default(1)
- expiredUrl String? @db.LongText // URL to redirect to for expired links
monitoringId String? @unique // cron job ID for monitoring
users ProjectUsers[]
@@ -174,19 +173,24 @@ model Domain {
id String @id @default(cuid())
slug String @unique
verified Boolean @default(false)
- target String?
- type String @default("redirect")
placeholder String @default("https://dub.co/help/article/what-is-dub")
description String?
- project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
- projectId String?
primary Boolean @default(false)
archived Boolean @default(false)
- publicStats Boolean @default(false)
+ expiredUrl String? @db.LongText // URL to redirect to for expired links
+ lastChecked DateTime @default(now())
links Link[]
+ project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ projectId String?
+
+ // TODO: migrate these attributes to Link model
+ target String?
+ type String @default("redirect")
clicks Int @default(0)
lastClicked DateTime? // when the link was last clicked
- lastChecked DateTime @default(now())
+ publicStats Boolean @default(false)
+
+ // these attributes will exist on both Link and Domain models
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt