| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { NextRequest, NextResponse } from "next/server";
- import { restApiFetch } from "@/utils/bagisto";
- export async function GET(req: NextRequest) {
- try {
- // 👇 取出所有前端传过来的查询参数
- const searchParams = req.nextUrl.searchParams;
- const page = searchParams.get("page");
- const limit = searchParams.get("limit");
- const status = searchParams.get("status");
- // 👇 构建查询参数数组(自动过滤空值)
- const queryParts: string[] = [];
- if (page) queryParts.push(`page=${page}`);
- if (limit) queryParts.push(`limit=${limit}`);
- if (status) queryParts.push(`status=${status}`);
- // 👇 最终拼接 URL
- let apiUrl = "/customer/orders";
- if (queryParts.length > 0) {
- apiUrl += "?" + queryParts.join("&");
- }
- console.log("最终请求API地址:", apiUrl);
- const response = await restApiFetch<any>({
- api: apiUrl,
- method: "GET",
- cache: "no-store",
- });
- return NextResponse.json(response.body,{
- status: response.status
- });
- } catch (error) {
- return NextResponse.json(
- {
- message: "Network error",
- error: error instanceof Error ? error.message : error,
- },
- { status: 500 }
- );
- }
- }
|