fix: handle null query params in API + add testing guide
This commit is contained in:
@@ -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. 验证查询参数
|
||||
|
||||
Reference in New Issue
Block a user