refactor: Creation d'un provider et d'un systeme de middleware

This commit is contained in:
Luc SORIGNET
2025-02-22 13:05:01 +01:00
parent c861239d48
commit 508847940c
18 changed files with 218 additions and 69 deletions

View File

@ -1,24 +1,5 @@
import { NextResponse } from 'next/server';
import createMiddleware from 'next-intl/middleware';
import { routing } from '@/i18n/routing';
const middleware = createMiddleware(routing);
import { stackMiddlewares } from "@/middlewares/stackHandler";
import { withLocale } from "@/middlewares/withLocale";
export default function handler(req) {
const { pathname, search } = req.nextUrl;
const locale = pathname.split('/')[1]; // Obtenez la locale actuelle
// Vérifiez si la route ne contient pas de locale
if (!pathname.startsWith('/fr') && !pathname.startsWith('/en')) {
// Redirigez vers la locale par défaut (fr) avec les paramètres de recherche
console.log('Redirecting to /fr');
return NextResponse.redirect(new URL(`/fr${pathname}${search}`, req.url));
}
return middleware(req);
}
export const config = {
// Match only internationalized pathnames
matcher: ['/', '/(fr|en)/:path*','/((?!api|_next|favicon.ico|favicon.svg).*)'],
};
const middlewares = [withLocale];
export default stackMiddlewares(middlewares);