nextjs请求的为json object stream方式,这是一种流的方式传输,需要用await等待一下,或是then
js
import { NextRequest, NextResponse } from "next/server";
// export const dynamic = 'force-dynamic' // defaults to auto
export async function POST(request: NextRequest) {
const body = await request.json();
console.log(body);
return new Response(JSON.stringify({ a:1, b:2 }), {
headers: { 'Content-Type': 'text/plain' },
})
}
export async function GET(request: Request) {
console.log(request.headers.get('cookie'));
return new Response(JSON.stringify({ c:3, d:4 }), {
headers: { 'Content-Type': 'text/plain',"set-cookie":'token=1234567890;path=/;HttpOnly;SameSite=Lax' },
})
}
如果直接用postman,nextjs是直接报500,这里需要稍微注意一下改成以下