middleware.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { routing } from "@/i18n/routing";
  2. import createMiddleware from "next-intl/middleware";
  3. import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
  4. function stackMiddleware(functions: Function[], index = 0): Function {
  5. const current = functions[index];
  6. if (current) {
  7. const next = stackMiddleware(functions, index + 1);
  8. return current(next);
  9. }
  10. return () => NextResponse.next();
  11. }
  12. function localMiddleware() {
  13. return async (request: NextRequest, _next: NextFetchEvent) => {
  14. const handleI18nRouting = createMiddleware(routing);
  15. return handleI18nRouting(request);
  16. };
  17. }
  18. const whiteRouters = ["/"];
  19. function authMiddleware(next: Function) {
  20. return async (request: NextRequest, res: NextResponse) => {
  21. const url = request.nextUrl;
  22. console.log(`🚀🚀🚀🚀🚀-> in middleware.ts on 24`, url);
  23. return next(request, res);
  24. };
  25. }
  26. export default stackMiddleware([authMiddleware, localMiddleware]);
  27. // 创建一个正则表达式对象
  28. export const config = {
  29. // todo use this to match the path
  30. matcher: ["/", "/(en|br)/:path*"],
  31. };