Something went wrong. Try again.
ATProto Social Bookmark
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839import { NextResponse } from 'next/server';import type { NextRequest } from 'next/server';import { routing } from '@/i18n/routing';
export function proxy(req: NextRequest) { const pathname = req.nextUrl.pathname;
// 静的メタデータや特定ルートならそのまま if ( pathname === '/manifest.webmanifest' || pathname === '/robots.txt' || pathname === '/sitemap.xml' || pathname === '/favicon.ico' ) { return; }
// すでに言語付きのパスならそのまま if (routing.locales.some((locale) => pathname.startsWith(`/${locale}`))) { return; }
// ブラウザの言語を判定 const acceptLanguage = req.headers.get('accept-language') || ''; const preferred = acceptLanguage.split(',')[0].split('-')[0]; // ex: "ja" or "en" const locale = (routing.locales.find(l => l === preferred) ?? routing.defaultLocale) as "en" | "ja";
// ルートにリダイレクト const url = req.nextUrl.clone(); url.pathname = `/${locale}${pathname}`; return NextResponse.redirect(url);}
export const config = { matcher: [ // 言語プレフィックスを自動付与する対象のパス '/((?!api|xrpc|.well-known|trpc|_next/static|_next/image|favicon.ico|sitemap\\.xml|robots\\.txt|manifest\\.webmanifest|.*\\.webmanifest|.*\\.png|.*\\.jpg|.*\\.svg|.*\\.ico|callback).*)', ],};