Aller au contenu

registerProxyAxios

Ce contenu n’est pas encore disponible dans votre langue.

registerProxyAxios<Config>(instance): void

Defined in: nextjs/registerProxyAxios.ts:102

Attach a request interceptor to an axios instance so every server-side request it makes carries the current session’s recording id (x-test-rcrd-id), letting the proxy tell concurrent replay sessions apart.

This is the axios counterpart to registerProxyFetch (which patches the global fetch). Use it for the axios instance(s) your SSR / Server Components make API calls through — it removes the need to hand-roll an interceptor plus a React.cache()-memoized next/headers reader:

import { registerProxyAxios } from 'test-proxy-recorder/nextjs';
registerProxyAxios(axiosForServer);
registerProxyAxios(axiosWithAuth);
  • No-op in production unless TEST_PROXY_RECORDER_ENABLED is set (the interceptor is not even attached).
  • No-op in the browser — the interceptor short-circuits when window exists, and the id is only readable inside a server request scope anyway.
  • Idempotent per instance: registering the same instance twice attaches one interceptor.
  • Never overwrites a recording id a caller set explicitly.

Config extends ProxyAxiosRequestConfig = ProxyAxiosRequestConfig

ProxyAxiosInstance<Config>

the axios instance to tag server-side requests on

void