| 1234567891011121314151617181920212223242526272829303132333435363738 |
- import { NextRequest, NextResponse } from "next/server";
- import { restApiFetch } from "@/utils/bagisto";
- import { getAuthToken } from "@/utils/helper";
- export async function POST(req: NextRequest) {
- try {
- const authorizationToken = getAuthToken(req); // 获取headers中的Authorization的值
- const params = await req.json();
- const response = await restApiFetch<{
- data: any; // 这个是返回结果的数据类型,暂时写成any,具体看后端反的数据结构再改成确定的类型1
- variables: {
- id: number; // 到时候你自己改看是number还是string
- }
- }>({
- api: '/gift/add',
- method:'POST',
- cache:'no-store',
- variables: params,
- guestToken: authorizationToken,
- });
- // 打印后端原始返回结构
- console.log('接口原始response.body =', JSON.stringify(response.body, null, 2));
- return NextResponse.json(response.body,{
- status: response.status,
- });
- } catch (error) {
- console.log('/gift/add --- ', error); // 调试用
- return NextResponse.json(
- {
- message: error instanceof Error ? error.message : "Network error",
- success: false,
- data: []
- },
- { status:500 }
- );
- }
- }
|