Files
novalon-website/src/middleware.ts
T
张翔 f5dec95a83 feat: 添加管理后台页面和功能,优化测试和性能配置
refactor: 重构页面导航和滚动逻辑,提升用户体验

test: 更新测试配置和用例,增加覆盖率和稳定性

perf: 优化性能指标和阈值,适应开发环境需求

ci: 添加Lighthouse CI工作流,集成性能测试

docs: 更新API文档和健康检查端点

fix: 修复登录页面和表单提交问题

style: 调整响应式布局和可访问性改进

chore: 更新依赖项和脚本配置
2026-03-24 10:11:30 +08:00

54 lines
1.3 KiB
TypeScript

import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
if (pathname.startsWith('/api/auth')) {
return NextResponse.next();
}
if (pathname.startsWith('/api/admin')) {
return NextResponse.next();
}
if (pathname.startsWith('/api/content')) {
return NextResponse.next();
}
const legacyApiPaths = [
'/api/config',
'/api/health',
];
const isLegacyApi = legacyApiPaths.some(path =>
pathname.startsWith(path) && !pathname.includes('/v1/') && !pathname.includes('/v2/')
);
if (isLegacyApi) {
const url = request.nextUrl.clone();
url.pathname = pathname.replace('/api/', '/api/v1/');
return NextResponse.rewrite(url);
}
if (pathname.startsWith('/api/docs') || pathname === '/api-docs') {
const response = NextResponse.next();
response.headers.set('X-API-Version', 'none');
return response;
}
const versionMatch = pathname.match(/\/api\/v(\d+)\//);
if (versionMatch) {
const response = NextResponse.next();
response.headers.set('X-API-Version', `v${versionMatch[1]}`);
return response;
}
return NextResponse.next();
}
export const config = {
matcher: '/api/:path*',
};