The open-source AI voice studio. Clone, dictate, create.
fix(landing): use public origin for download redirects behind proxies (#498)
Shekhar Kumare3f7cd9d00e2
diff --git a/landing/src/app/download/[platform]/route.ts b/landing/src/app/download/[platform]/route.tsindex b3b0b9b8..05b5077f 100644--- a/landing/src/app/download/[platform]/route.ts+++ b/landing/src/app/download/[platform]/route.ts@@ -15,17 +15,32 @@ const PLATFORM_ALIAS: Record<string, string> = {windows: 'windows',};+function getPublicOrigin(request: NextRequest): string {+ const forwardedHost = request.headers.get('x-forwarded-host');+ const forwardedProto = request.headers.get('x-forwarded-proto');++ if (forwardedHost && forwardedProto) {+ // Behind reverse proxies/CDNs, request.url can be an internal origin+ // (for example localhost:8080). Prefer forwarded headers so redirects+ // keep users on the public domain.+ return `${forwardedProto}://${forwardedHost}`;+ }++ return new URL(request.url).origin;+}+export async function GET(request: NextRequest,{ params }: { params: Promise<{ platform: string }> },) {+ const origin = getPublicOrigin(request);const { platform } = await params;// No prebuilt Linux binary yet — send straight to the build-from-source page.if (platform === 'linux') {- return NextResponse.redirect(new URL('/linux-install', request.url), 307);+ return NextResponse.redirect(new URL('/linux-install', origin), 307);}const normalized = PLATFORM_ALIAS[platform];- const target = new URL('/download', request.url);+ const target = new URL('/download', origin);if (normalized) target.searchParams.set('platform', normalized);return NextResponse.redirect(target, 307);}