middleware.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. return next(request, res);
  23. };
  24. }
  25. export default stackMiddleware([authMiddleware, localMiddleware]);
  26. // 创建一个正则表达式对象
  27. export const config = {
  28. // todo use this to match the path
  29. matcher: ["/", "/(en|br)/:path*"],
  30. };