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.

fixed UA parser, added logs

Steven Teye351e3a56481
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index 69914f584b..3297cdb2a7 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -20,6 +20,8 @@ export default async function LinkMiddleware(
}>(`${domain}:${key}`);
const { url: target, password, proxy } = response || {};
+ console.log(domain, key, target, password, proxy);
+
if (target) {
// special case for link health monitoring with planetfall.io :)
if (!req.headers.get("dub-no-track")) {
@@ -27,11 +29,8 @@ export default async function LinkMiddleware(
}
if (password && !req.cookies.get("dub_authenticated")) {
- return NextResponse.rewrite(
- process.env.NODE_ENV === "development"
- ? `http://localhost:3000/auth/${domain}/${key}`
- : `https://dub.sh/auth/${domain}/${key}`,
- );
+ console.log("rewriting onto to password page");
+ return NextResponse.rewrite(`https://dub.sh/auth/${domain}/${key}`);
}
const isBot = detectBot(req);
diff --git a/lib/stats.ts b/lib/stats.ts
index 0ea2d93837..32c77ff6f6 100644
--- a/lib/stats.ts
+++ b/lib/stats.ts
@@ -144,9 +144,9 @@ export function processData(
const refererData = data.map(({ referer }) => {
try {
const url = referer ? new URL(referer) : null;
- return { domain: url?.hostname || '(direct)' };
+ return { domain: url?.hostname || "(direct)" };
} catch (e) {
- return { domain: '(invalid)' };
+ return { domain: "(invalid)" };
}
});
@@ -157,7 +157,7 @@ export function processData(
clicksData,
locationData,
deviceData,
- refererData
+ refererData,
};
}
@@ -239,7 +239,9 @@ export interface RefererStatsProps {
count: number;
}
-export const processRefererData = (data: StatsProps['refererData']): RefererStatsProps[] => {
+export const processRefererData = (
+ data: StatsProps["refererData"],
+): RefererStatsProps[] => {
const results =
data && data.length > 0
? data.reduce<Record<string, number>>((acc, d) => {
@@ -253,7 +255,7 @@ export const processRefererData = (data: StatsProps['refererData']): RefererStat
return Object.entries(results)
.map(([display, count]) => ({
display,
- count
+ count,
}))
.sort((a, b) => b.count - a.count);
};
@@ -271,10 +273,11 @@ export const dummyData: StatsProps = {
// @ts-ignore
deviceData: null,
// @ts-ignore
- refererData: null
+ refererData: null,
};
export const handleDeviceEdgeCases = (ua: string): string => {
+ if (!ua) return "Unknown";
if (ua.includes("curl")) {
return "Curl Request";
} else if (ua.includes("Slackbot")) {