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 domain stats page 404

Steven Teyb89c0852775c
diff --git a/apps/web/app/ui/stats/index.tsx b/apps/web/app/ui/stats/index.tsx
index 242fe9ee29..6ef6a691e0 100644
--- a/apps/web/app/ui/stats/index.tsx
+++ b/apps/web/app/ui/stats/index.tsx
@@ -61,13 +61,15 @@ export default function Stats({
let {
slug,
domain: domainSlug,
- key,
+ key, // might wanna set the defaule to "_root" here
} = params as {
slug?: string;
domain?: string;
key: string;
};
- if (staticKey) key = staticKey;
+ if (staticKey) {
+ key = staticKey;
+ }
const interval = searchParams.get("interval") || "24h";
@@ -83,7 +85,10 @@ export default function Stats({
return {
basePath: `/${slug}/${domainSlug}/${key}`,
domain: domainSlug,
- endpoint: `/api/links/${key}/stats`,
+ endpoint:
+ key === "_root"
+ ? `/api/projects/${slug}/domains/${domainSlug}/stats`
+ : `/api/links/${key}/stats`,
};
// Generic Dub.co link page, e.g. app.dub.co/links/steven
diff --git a/apps/web/components/app/domains/domain-card.tsx b/apps/web/components/app/domains/domain-card.tsx
index 6e95e2f6aa..ee4cc344e3 100644
--- a/apps/web/components/app/domains/domain-card.tsx
+++ b/apps/web/components/app/domains/domain-card.tsx
@@ -30,7 +30,7 @@ export default function DomainCard({ props }: { props: DomainProps }) {
});
const { data: clicks } = useSWR<number>(
- slug && `/api/projects/${slug}/domains/${domain}/clicks`,
+ slug && `/api/projects/${slug}/domains/${domain}/stats/clicks`,
fetcher,
{
dedupingInterval: 15000,
diff --git a/apps/web/components/layout/app/project-select.tsx b/apps/web/components/layout/app/project-select.tsx
index 5163dffe47..36c8bd1dfa 100644
--- a/apps/web/components/layout/app/project-select.tsx
+++ b/apps/web/components/layout/app/project-select.tsx
@@ -86,6 +86,7 @@ export default function ProjectSelect() {
<div className="flex items-center space-x-3 pr-2">
<img
src={selected.image}
+ referrerPolicy="no-referrer"
alt={selected.id || selected.name}
className="h-8 w-8 flex-none overflow-hidden rounded-full"
/>
diff --git a/apps/web/components/stats/index.tsx b/apps/web/components/stats/index.tsx
index 7dd42fdea6..a4b6d5dc2c 100644
--- a/apps/web/components/stats/index.tsx
+++ b/apps/web/components/stats/index.tsx
@@ -54,7 +54,10 @@ export default function Stats({ staticDomain }: { staticDomain?: string }) {
key === "_root" ? "" : `/${encodeURIComponent(key)}`
}`,
domain: domainSlug,
- endpoint: `/api/links/${encodeURIComponent(key)}/stats`,
+ endpoint:
+ key === "_root"
+ ? `/api/projects/${slug}/domains/${domainSlug}/stats`
+ : `/api/links/${encodeURIComponent(key)}/stats`,
};
// Generic Dub.sh link page, e.g. app.dub.co/links/steven
diff --git a/apps/web/pages/api/links/[key]/stats/[endpoint].ts b/apps/web/pages/api/links/[key]/stats/[endpoint].ts
index 5300a93714..60c9b3eb40 100644
--- a/apps/web/pages/api/links/[key]/stats/[endpoint].ts
+++ b/apps/web/pages/api/links/[key]/stats/[endpoint].ts
@@ -26,7 +26,7 @@ export default withLinksAuth(
});
if (!response) {
- return res.status(405).end(`Method ${req.method} Not Allowed`);
+ return res.status(404).end("Not Found");
}
return res.status(200).json(response);
diff --git a/apps/web/pages/api/projects/[slug]/domains/[domain]/stats/[endpoint].ts b/apps/web/pages/api/projects/[slug]/domains/[domain]/stats/[endpoint].ts
new file mode 100644
index 0000000000..0e9afb8d95
--- /dev/null
+++ b/apps/web/pages/api/projects/[slug]/domains/[domain]/stats/[endpoint].ts
@@ -0,0 +1,31 @@
+import { withProjectAuth } from "#/lib/auth";
+import { IntervalProps, getStats } from "#/lib/stats";
+
+export default withProjectAuth(async (req, res, project) => {
+ // GET /api/projects/[slug]/domains/[domain]/clicks - get # of clicks on root of domain (e.g. dub.sh, vercel.fyi)
+ if (req.method === "GET") {
+ const { domain, endpoint, interval } = req.query as {
+ domain: string;
+ endpoint: string;
+ interval: IntervalProps;
+ };
+ if (
+ (interval === "all" || interval === "90d") &&
+ (!project || project.plan === "free")
+ ) {
+ return res.status(403).end("Forbidden: Require higher plan");
+ }
+
+ const response = await getStats({
+ domain,
+ key: "_root",
+ endpoint,
+ interval,
+ });
+
+ return res.status(200).json(response);
+ } else {
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+});
diff --git a/packages/ui/package.json b/packages/ui/package.json
index b615bfaef3..1b5b836823 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -1,7 +1,7 @@
{
"name": "@dub/ui",
"description": "UI components for Dub.co",
- "version": "0.0.11",
+ "version": "0.0.12",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
diff --git a/packages/ui/src/avatar.tsx b/packages/ui/src/avatar.tsx
index 97c31f8d5b..7968db8781 100644
--- a/packages/ui/src/avatar.tsx
+++ b/packages/ui/src/avatar.tsx
@@ -25,6 +25,7 @@ export function Avatar({
return (
<img
alt={`Avatar for ${user?.name || user?.email}`}
+ referrerPolicy="no-referrer"
src={
user?.image ||
`https://avatars.dicebear.com/api/micah/${user?.email}.svg`