31 lines
1007 B
TypeScript
31 lines
1007 B
TypeScript
import type { NextRequest } from 'next/server';
|
|
import createMiddleware from 'next-intl/middleware';
|
|
|
|
import { routing } from './i18n/routing';
|
|
|
|
/**
|
|
* Locale negotiation at the edge.
|
|
*
|
|
* Note the filename: Next.js 16 renamed the `middleware` convention to `proxy`.
|
|
* `middleware.ts` still works but is deprecated, so this uses the current name.
|
|
*
|
|
* Responsibilities are deliberately narrow — resolve a locale, rewrite or
|
|
* redirect, and nothing else. Proxy code runs on every request and may be
|
|
* deployed to a CDN edge, so it must not reach for the database or shared
|
|
* application state.
|
|
*/
|
|
const handleI18nRouting = createMiddleware(routing);
|
|
|
|
export function proxy(request: NextRequest) {
|
|
return handleI18nRouting(request);
|
|
}
|
|
|
|
export const config = {
|
|
/**
|
|
* Everything except API routes, Next internals and files with an extension.
|
|
* Matching static assets would add a proxy hop to every image and font for
|
|
* no benefit.
|
|
*/
|
|
matcher: '/((?!api|_next|_vercel|.*\\..*).*)',
|
|
};
|