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.

fix stats page 404 error

Steven Tey94902afa47f2
diff --git a/app/[domain]/stats/[key]/page.tsx b/app/[domain]/stats/[key]/page.tsx
index e7d5f14e1c..71439b0d04 100644
--- a/app/[domain]/stats/[key]/page.tsx
+++ b/app/[domain]/stats/[key]/page.tsx
@@ -13,10 +13,8 @@ export async function generateMetadata({
}) {
const data = await getLinkViaEdge(params.domain, params.key);
- // if the link is explicitly private (publicStats === false)
- // or if the link doesn't exist in database (data === undefined) and is not a dub.sh link
- // (we need to exclude dub.sh public demo links here)
- if (data?.publicStats === 0 || (!data && params.domain !== "dub.sh")) {
+ // if the link doesn't exist or is explicitly private (publicStats === false)
+ if (!data || data?.publicStats === 0) {
return;
}
@@ -29,15 +27,6 @@ export async function generateMetadata({
});
}
-export async function generateStaticParams() {
- return [
- {
- domain: "dub.sh",
- key: "github",
- },
- ];
-}
-
export default async function StatsPage({
params,
}: {
@@ -45,7 +34,7 @@ export default async function StatsPage({
}) {
const data = await getLinkViaEdge(params.domain, params.key);
- if (data?.publicStats === 0 || (!data && params.domain !== "dub.sh")) {
+ if (!data || data?.publicStats === 0) {
notFound();
}
diff --git a/app/dub.sh/stats/[key]/page.tsx b/app/dub.sh/stats/[key]/page.tsx
new file mode 100644
index 0000000000..be7598136d
--- /dev/null
+++ b/app/dub.sh/stats/[key]/page.tsx
@@ -0,0 +1,58 @@
+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 getLinkViaEdge(params.domain, params.key);
+
+ // if the link is explicitly private (publicStats === false)
+ // (we allow !data because that means it's an ephemeral dub.sh demo link that doesn't exist in the db)
+ if (data?.publicStats === 0) {
+ return;
+ }
+
+ return constructMetadata({
+ title: `Stats for ${params.domain}/${params.key} - Dub`,
+ description: `Stats page for ${params.domain}/${params.key}${
+ data?.url ? `, which redirects to ${data.url}` : ""
+ }.`,
+ image: `https://${params.domain}/api/og/stats?domain=${params.domain}&key=${params.key}`,
+ });
+}
+
+export async function generateStaticParams() {
+ return [
+ {
+ domain: "dub.sh",
+ key: "github",
+ },
+ ];
+}
+
+export default async function StatsPage({
+ params,
+}: {
+ params: { domain: string; key: string };
+}) {
+ const data = await getLinkViaEdge(params.domain, params.key);
+
+ if (data?.publicStats === 0) {
+ notFound();
+ }
+
+ return (
+ <div className="bg-gray-50">
+ <Suspense fallback={<div className="h-screen w-full bg-gray-50" />}>
+ <Stats staticDomain={params.domain} />
+ </Suspense>
+ </div>
+ );
+}
diff --git a/app/ui/stats/toggle.tsx b/app/ui/stats/toggle.tsx
index 44b65d1da4..320bf318e4 100644
--- a/app/ui/stats/toggle.tsx
+++ b/app/ui/stats/toggle.tsx
@@ -58,7 +58,6 @@ export default function Toggle() {
content={
<div className="w-full p-2 md:w-48">
{INTERVALS.map(({ display, slug }) =>
- !(domain === "dub.sh" && key === "github") &&
(slug === "all" || slug === "90d") &&
(!plan || plan === "free") ? (
<Tooltip