From 2297f01e6071ecbc0e2bdc983cbb61d5ee62fd68 Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Mon, 31 Aug 2026 12:03:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(middleware):=20=E8=BF=81=E7=A7=BB=20mi?= =?UTF-8?q?ddleware=20=E8=87=B3=20proxy=EF=BC=88Next=2016=20=E5=BC=83?= =?UTF-8?q?=E7=94=A8=E7=BA=A6=E5=AE=9A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/proxy.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/proxy.ts b/src/proxy.ts index 906052d..e333055 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -8,7 +8,8 @@ interface JwtPayload { } // ============ Edge-compatible JWT 验证 ============ -// Next.js Middleware 运行在 Edge Runtime,不能依赖 jsonwebtoken 的 Node crypto。 +// Next.js Proxy(原 Middleware 约定,Next 16 起重命名)运行在 Edge Runtime, +// 不能依赖 jsonwebtoken 的 Node crypto。 // 这里使用 Web Crypto API 实现 HS256 签名验证,与 API 路由中的 jsonwebtoken 共享同一密钥。 function base64urlToBuffer(value: string): Uint8Array { @@ -65,7 +66,7 @@ async function verifyAccessTokenEdge(token: string): Promise { return payload; } -// ============ Middleware ============ +// ============ Proxy(原 Middleware,Next 16 弃用 middleware 约定) ============ function redirectToLogin(request: NextRequest, pathname: string): NextResponse { const loginUrl = new URL('/admin/login', request.url); @@ -73,7 +74,7 @@ function redirectToLogin(request: NextRequest, pathname: string): NextResponse { return NextResponse.redirect(loginUrl); } -export async function middleware(request: NextRequest) { +export async function proxy(request: NextRequest) { const { pathname } = request.nextUrl; // 只处理 /admin 路由(除了登录页和 API 路由)