teableio/teable

View on GitHub
apps/nextjs-app/src/middleware.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
import { getLocaleDetection } from './lib/i18n/getLocale';

export function middleware(request: NextRequest) {
  const locale = getLocaleDetection({
    req: request,
    i18n: {
      defaultLocale: 'en',
      locales: ['en', 'de', 'zh', 'fr', 'ja', 'ru'],
    },
  });

  const response = NextResponse.next();
  response.headers.set('X-Server-Locale', locale);
  return response;
}

export const config = {
  /*
   * Match all request paths except for the ones starting with:
   * - api (API routes)
   * - _next/static (static files)
   * - _next/image (image optimization files)
   * - favicon.ico (favicon file)
   * - socket (Ws)
   */
  matcher: '/((?!api|_next/static|_next/image|favicon.ico|socket).*)',
};