Skip to content

Commit

Permalink
web: redirect /l/download to App Store
Browse files Browse the repository at this point in the history
fixes #666
  • Loading branch information
dcposch committed Feb 10, 2024
1 parent d84d258 commit a7fbd79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions apps/daimo-web/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

import { detectPlatform, downloadMetadata } from "./utils/platform";

export function middleware(request: NextRequest) {
if (request.nextUrl.pathname === "/l/download") {
return redirectMobileToAppStore(request);
}
return NextResponse.next();
}

function redirectMobileToAppStore(request: NextRequest) {
const ua = request.headers.get("user-agent") || "";
const platform = detectPlatform(ua);
const { url } = downloadMetadata[platform];
return NextResponse.redirect(url);
}
2 changes: 1 addition & 1 deletion apps/daimo-web/src/utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function detectPlatform(ua: string): PlatformType {
// From https://dev.to/konyu/using-javascript-to-determine-whether-the-client-is-ios-or-android-4i1j
if (/android/i.test(ua)) {
return "android";
} else if (/iPhone|iPod/.test(ua)) {
} else if (/iPhone|iPod|iPad/.test(ua)) {
return "ios";
}
return "other";
Expand Down

0 comments on commit a7fbd79

Please sign in to comment.