The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix edge/stats/clicks bug
Steven Teye6d2071ebd5a
diff --git a/components/home/link-card.tsx b/components/home/link-card.tsxindex 660ed660d0..8e3f93bfc0 100644--- a/components/home/link-card.tsx+++ b/components/home/link-card.tsx@@ -115,7 +115,7 @@ export default function LinkCard({});const { data: clicks } = useSWR<number>(- `/api/edge/links/${key}/clicks`,+ `/api/edge/links/${key}/stats/clicks`,fetcher,{// avoid revalidation on focus when modals are open to prevent rerenderingdiff --git a/lib/stats.ts b/lib/stats.tsindex 7667062ea1..a81c5a0236 100644--- a/lib/stats.ts+++ b/lib/stats.ts@@ -132,7 +132,7 @@ export const getStats = async ({const clicks = response.rows[0]["clicks"];return clicks || "0";} catch (e) {- console.log(e);+ console.log(e, "Potential reason: Link is not in MySQL DB");}}diff --git a/pages/api/edge/links/[key]/stats/[endpoint].ts b/pages/api/edge/links/[key]/stats/[endpoint].tsindex 73b420592c..46de9da4a4 100644--- a/pages/api/edge/links/[key]/stats/[endpoint].ts+++ b/pages/api/edge/links/[key]/stats/[endpoint].ts@@ -10,16 +10,19 @@ export const config = {export default async function handler(req: NextRequest) {if (req.method === "GET") {const key = req.nextUrl.searchParams.get("key");- const interval = req.nextUrl.searchParams.get("interval") || "24h";+ const interval = req.nextUrl.searchParams.get("interval");const endpoint = req.nextUrl.searchParams.get("endpoint");let domain = req.headers.get("host");if (isHomeHostname(domain)) domain = "dub.sh";- const data = await getLinkViaEdge(domain, key);- if (!data?.publicStats) {- return new Response(`Stats for this link are not public`, {- status: 403,- });+ // don't need to check if the link has public stats if the link is dub.sh/github (demo link)+ if (!(domain === "dub.sh" || key === "github")) {+ const data = await getLinkViaEdge(domain, key);+ if (!data?.publicStats) {+ return new Response(`Stats for this link are not public`, {+ status: 403,+ });+ }}const response = await getStats({