Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/site/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { redirect } from 'next/navigation';

/**
* Root page - redirects are handled by proxy.ts middleware
* This page should never actually render as the middleware intercepts and redirects
* But Next.js requires a page component for the route to be recognized
*/
export default function RootPage() {
// Fallback redirect if middleware didn't handle it
redirect('/en/docs');
}
30 changes: 28 additions & 2 deletions packages/site/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
import { createI18nMiddleware } from 'fumadocs-core/i18n/middleware';
import { i18n } from '@/lib/i18n';
import { NextResponse, NextRequest, NextFetchEvent } from 'next/server';

export default createI18nMiddleware(i18n);
// Create fumadocs middleware
const fumadocsMiddleware = createI18nMiddleware(i18n);

export default function proxy(request: NextRequest, event: NextFetchEvent) {
const path = request.nextUrl.pathname;

// Handle root path separately with custom language detection
if (path === '/') {
const acceptLanguage = request.headers.get('accept-language') || '';

// Simple language detection: check if zh is in Accept-Language
if (acceptLanguage.toLowerCase().includes('zh')) {
// Redirect to Chinese docs
const url = request.nextUrl.clone();
url.pathname = '/cn/docs';
return NextResponse.redirect(url);
} else {
// Redirect to default language (English)
const url = request.nextUrl.clone();
url.pathname = '/en/docs';
return NextResponse.redirect(url);
}
}

// For all other paths, pass through to fumadocs middleware
return fumadocsMiddleware(request, event);
}

export const config = {
// Matcher ignoring `/_next/` and `/api/`
// You may need to adjust it to ignore static assets in `/public` folder
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|logo.svg).*)'],
};