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.

Update link.ts

Steven Teydf5dafc6c1f8
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index 63133f3eeb..c8720fb1f6 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -88,26 +88,31 @@ export default async function LinkMiddleware(
// rewrite to target URL if link cloaking is enabled
if (rewrite) {
- return NextResponse.rewrite(new URL(target, req.url), DUB_HEADERS);
- } else if (isBot && proxy) {
+ return NextResponse.rewrite(target, DUB_HEADERS);
+
// rewrite to proxy page (/_proxy/[domain]/[key]) if it's a bot and proxy is enabled
+ } else if (isBot && proxy) {
return NextResponse.rewrite(
new URL(`/proxy/${domain}/${encodeURIComponent(key)}`, req.url),
);
- } else if (ios && userAgent(req).os?.name === "iOS") {
+
// redirect to iOS link if it is specified and the user is on an iOS device
+ } else if (ios && userAgent(req).os?.name === "iOS") {
return NextResponse.redirect(getFinalUrl(ios, { req }), DUB_HEADERS);
- } else if (android && userAgent(req).os?.name === "Android") {
+
// redirect to Android link if it is specified and the user is on an Android device
+ } else if (android && userAgent(req).os?.name === "Android") {
return NextResponse.redirect(getFinalUrl(android, { req }), DUB_HEADERS);
- } else if (geo && country && country in geo) {
+
// redirect to geo-specific link if it is specified and the user is in the specified country
+ } else if (geo && country && country in geo) {
return NextResponse.redirect(
getFinalUrl(geo[country], { req }),
DUB_HEADERS,
);
- } else {
+
// regular redirect
+ } else {
return NextResponse.redirect(getFinalUrl(target, { req }), DUB_HEADERS);
}
} else {