a3915377bd
- Added RootLayout component to handle locale and message loading. - Created Home page with header, about info, products, and story sections. - Developed ProductPage for displaying product categories and products. - Implemented ProductsPage to list product categories with banners. - Added Projects page with a grid layout for project display. - Configured server settings for port and host. - Established navigation and routing for internationalization. - Set up request handling for locale and message retrieval. - Defined routing structure for supported locales. - Created middleware for locale-based routing. - Defined layout parameters for locale handling.
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import type { NextRequest } from 'next/server';
|
|
|
|
const PUBLIC_FILE = /\.(.*)$/;
|
|
const locales = ['en', 'fa'];
|
|
const defaultLocale = 'en';
|
|
|
|
export function middleware(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
|
|
// Ignore public files and API routes
|
|
if (
|
|
pathname.startsWith('/api') ||
|
|
PUBLIC_FILE.test(pathname)
|
|
) {
|
|
return NextResponse.next();
|
|
}
|
|
|
|
// Check if the pathname already includes a locale
|
|
const pathnameIsMissingLocale = locales.every(
|
|
(locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`
|
|
);
|
|
|
|
if (pathnameIsMissingLocale) {
|
|
// Redirect to default locale
|
|
return NextResponse.redirect(
|
|
new URL(`/${defaultLocale}${pathname}`, request.url)
|
|
);
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
/*
|
|
Match all request paths except for:
|
|
- static files (/_next/static/)
|
|
- API routes (/api/)
|
|
*/
|
|
'/((?!_next/static|_next/image|favicon.ico|api).*)',
|
|
],
|
|
}; |