accounts/dashboard/proxy.ts
Haitao Pan 4976ca1efd fix(dashboard): eliminate middleware deprecation warning
- Rename middleware.ts → proxy.ts
- Update to use default proxy export (Next.js 16)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-11-06 11:40:15 +08:00

27 lines
719 B
TypeScript

import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
function stripTrailingSlashes(pathname: string) {
if (pathname.length <= 1) return pathname
return pathname.replace(/\/+$/u, '')
}
export default async function proxy(request: NextRequest) {
const { pathname } = request.nextUrl
const isApiRoute = pathname === '/api' || pathname.startsWith('/api/')
const shouldStrip = isApiRoute && pathname.length > 1 && pathname.endsWith('/')
if (!shouldStrip) {
return NextResponse.next()
}
const url = request.nextUrl.clone()
url.pathname = stripTrailingSlashes(pathname)
return NextResponse.rewrite(url)
}
export const config = {
matcher: ['/api/:path*'],
}