小编Em *_*uan的帖子

自定义应用程序 Next.js 13 后中间件无法工作

我正在学习 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)

javascript node.js next.js

1
推荐指数
1
解决办法
3999
查看次数

标签 统计

javascript ×1

next.js ×1

node.js ×1