| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { NextRequest, NextResponse } from "next/server";
- import { restApiFetch } from "@/utils/bagisto";
- export async function GET(req: NextRequest) {
- try {
- // 👇 取出所有前端传过来的查询参数
- const searchParams = req.nextUrl.searchParams;
- const track_number = searchParams.get("track_number");
-
- // 👇 构建查询参数数组(自动过滤空值)
- const queryParts: string[] = [];
- if (track_number) queryParts.push(`track_number=${track_number}`);
-
- // 👇 最终拼接 URL
- let apiUrl = "/customer/orders/tracking";
- 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 }
- );
- }
- }
|