跳转到内容

getRecordingId

此内容尚不支持你的语言。

getRecordingId(requestHeaders): string | null

Defined in: nextjs/middleware.ts:96

Get the recording ID from the request if present Useful for manually adding the header to fetch requests in Next.js

Headers | NextJSRequest

Next.js headers object or NextRequest from next/server

string | null

The recording ID if present, null otherwise

// In your API route or server component
import { getRecordingId } from 'test-proxy-recorder/nextjs';
import { headers } from 'next/headers';
export async function GET() {
const recordingId = getRecordingId(headers());
const response = await fetch('http://localhost:8100/api/data', {
headers: {
...(recordingId && { 'x-test-rcrd-id': recordingId })
}
});
return Response.json(await response.json());
}