fix: handle null query params in API + add testing guide

This commit is contained in:
2026-01-27 21:39:17 +08:00
parent f81f51e508
commit 11a876ebbe
2 changed files with 165 additions and 4 deletions
+4 -4
View File
@@ -65,12 +65,12 @@ export async function POST(request: NextRequest) {
}
export async function GET(request: NextRequest) {
// 1. 解析查询参数
// 1. 解析查询参数(将 null 转换为 undefined
const searchParams = request.nextUrl.searchParams;
const queryParams = {
year: searchParams.get('year'),
limit: searchParams.get('limit'),
offset: searchParams.get('offset'),
year: searchParams.get('year') || undefined,
limit: searchParams.get('limit') || undefined,
offset: searchParams.get('offset') || undefined,
};
// 2. 验证查询参数