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 路由)