2025-05-05 14:53:47 +00:00
|
|
|
import createMiddleware from "next-intl/middleware";
|
|
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
|
import { locales } from "@/config";
|
2024-11-26 03:09:48 +00:00
|
|
|
|
|
|
|
|
export default async function middleware(request: NextRequest) {
|
|
|
|
|
// Step 1: Use the incoming request (example)
|
2025-05-05 14:53:47 +00:00
|
|
|
const defaultLocale = request.headers.get("dashcode-locale") || "in";
|
|
|
|
|
|
2024-11-26 03:09:48 +00:00
|
|
|
// Step 2: Create and call the next-intl middleware (example)
|
|
|
|
|
const handleI18nRouting = createMiddleware({
|
|
|
|
|
locales,
|
2025-05-05 14:53:47 +00:00
|
|
|
defaultLocale,
|
2024-11-26 03:09:48 +00:00
|
|
|
});
|
|
|
|
|
const response = handleI18nRouting(request);
|
|
|
|
|
|
2025-05-05 14:53:47 +00:00
|
|
|
// Step 3: Alter the response (example)
|
|
|
|
|
response.headers.set("dashcode-locale", defaultLocale);
|
2024-11-26 03:09:48 +00:00
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
2025-05-05 14:53:47 +00:00
|
|
|
|
2024-11-26 03:09:48 +00:00
|
|
|
export const config = {
|
|
|
|
|
// Match only internationalized pathnames
|
2025-05-05 14:53:47 +00:00
|
|
|
matcher: ["/", "/(ar|in|en)/:path*"],
|
|
|
|
|
};
|