import createMiddleware from "next-intl/middleware"; import { NextRequest, NextResponse } from "next/server"; import { routing } from "./i18n/routing"; const intlMiddleware = createMiddleware(routing); export default function middleware(request: NextRequest) { const { pathname } = request.nextUrl; // Abaikan semua static file dan asset const isStaticAsset = pathname.startsWith("/api") || pathname.startsWith("/_next") || pathname.startsWith("/favicon") || pathname.startsWith("/assets") || pathname.startsWith("/static") || pathname.startsWith("/images") || pathname.startsWith("/icons") || pathname.match(/\.(png|jpg|jpeg|gif|webp|svg|ico)$/); if (isStaticAsset) { return NextResponse.next(); } // Jika sudah dalam /in jalankan intl middleware if (pathname.startsWith("/in")) { return intlMiddleware(request); } // Redirect otomatis ke /in const url = request.nextUrl.clone(); url.pathname = `/in${pathname}`; return NextResponse.redirect(url); } export const config = { matcher: ["/((?!_next|api|favicon.ico|assets|static|images|icons).*)"], }; // import createMiddleware from "next-intl/middleware"; // import { NextRequest, NextResponse } from "next/server"; // import { locales } from "@/config"; // import { routing } from "./i18n/routing"; // // export default async function middleware(request: NextRequest) { // // // Step 1: Use the incoming request (example) // // const defaultLocale = "in"; // // // const defaultLocale = request.headers.get("dashcode-locale") || "in"; // // // Step 2: Create and call the next-intl middleware (example) // // const handleI18nRouting = createMiddleware({ // // locales: ["in", "en"], // // defaultLocale: "in", // // }); // // const response = handleI18nRouting(request); // // // Step 3: Alter the response (example) // // response.headers.set("dashcode-locale", defaultLocale); // // return response; // // } // export default createMiddleware(routing); // export const config = { // // Match only internationalized pathnames // matcher: ["/", "/(in|en)/:path*"], // };