Next.js 15 site for گروه بازرگانی بین المللی آریو مجد آسیا, rebuilt from majdtrading.com. Persian, English and Arabic; RTL and LTR. - Pages: home, about, contact, six product categories, blog index and detail - i18n: prose in per-locale JSON, structure in TypeScript, drift checked by `npm run i18n:check`. Blog stays single-language by design - Meshkee backend: blog content, tenant resolution, session via the customer portal, and /meshkee/sitemap-config.json - Live market data from livedata.ir, cached server-side once a minute - Self-hosted fonts: IRANYekan (fa), IBM Plex Sans Arabic (ar), Space Grotesk and BBH Bartle (Latin) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
27 lines
913 B
TypeScript
27 lines
913 B
TypeScript
import { NextResponse, type NextRequest } from "next/server";
|
|
import { locales, defaultLocale } from "@/i18n/config";
|
|
|
|
const PUBLIC_FILE = /\.(.*)$/;
|
|
|
|
/**
|
|
* Sends every un-prefixed path to a locale-prefixed one. Today `fa` is the only
|
|
* shipped locale; once `en` / `ar` are added, negotiate on `Accept-Language`
|
|
* here and the rest of the app needs no changes.
|
|
*/
|
|
export function middleware(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
|
|
const hasLocale = locales.some(
|
|
(locale) => pathname === `/${locale}` || pathname.startsWith(`/${locale}/`)
|
|
);
|
|
if (hasLocale || PUBLIC_FILE.test(pathname)) return NextResponse.next();
|
|
|
|
const url = request.nextUrl.clone();
|
|
url.pathname = `/${defaultLocale}${pathname === "/" ? "" : pathname}`;
|
|
return NextResponse.redirect(url);
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/((?!api|_next/static|_next/image|images|fonts|favicon.ico).*)"],
|
|
};
|