我正在学习 Next.js - 版本 13,并尝试根据标准文档自定义 next.js 应用程序。但不知何故,中间件没有被调用。我想我在这里做错了什么。如果您有时间,请查看该问题。
这是 middleware.ts 的代码更改:
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { AUTHORIZATION_TOKEN, COOKIE_TOKEN } from "@libs/constants";
import { verify } from "@libs/token";
export const config = {
matcher: ["/admin/:path*", "/signin", "/api/:path*"],
};
export async function middleware(request: NextRequest) {
const url = request.nextUrl.clone();
const regex = new RegExp('\\/api\\/(category|product|cart|coupon|auth)\\/(create|update|delete)', 'i')
let matcher: any = regex.exec(url.pathname);
let token: any;
let isValidToken: any;
if (matcher && matcher[0]) {
token = …Run Code Online (Sandbox Code Playgroud)