Files
yanshi2/middleware.ts
2026-04-15 09:29:54 +00:00

29 lines
885 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
/**
* 中间件:主要用于 API 路由的认证检查
* 客户端的 token 验证在页面组件中处理(因为 middleware 无法访问 localStorage
*/
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl
// API 路由的认证检查在各自的 route.ts 中处理
// 页面路由的认证检查在客户端组件中处理(使用 useAuth hook
return NextResponse.next()
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
'/((?!api|_next/static|_next/image|favicon.ico).*)',
],
}