Skip to content

Commit d859e20

Browse files
docs: add middleware tunneling to README
1 parent 4005dc8 commit d859e20

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,26 @@ For example, to send all logs except for debug logs to Axiom:
209209
export NEXT_PUBLIC_AXIOM_LOG_LEVEL=info
210210
```
211211
212+
## Middleware tunneling (beta)
213+
214+
Axiom supports using `middleware.ts` files to proxy logs and webVitals to Axiom, this avoids the need to declare the `AXIOM_TOKEN` as a public environment variable.
215+
216+
To enable this feature, in your middleware.ts file, add the following code:
217+
218+
```ts
219+
import { axiomMiddleware } from 'next-axiom';
220+
221+
export default axiomMiddleware();
222+
223+
export const config = {
224+
matcher: '/_axiom/:path*', // Makes it so that the middleware only fires for requests that match this path
225+
};
226+
```
227+
228+
and in your environment variables, change the `NEXT_PUBLIC_AXIOM_TOKEN` to `AXIOM_TOKEN`.
229+
230+
This will proxy all requests to `/_axiom/logs` and `/_axiom/web-vitals` to Axiom using the middleware as a proxy layer.
231+
212232
## Capture errors
213233
214234
To capture routing errors, use the [error handling mechanism of Next.js](https://nextjs.org/docs/app/building-your-application/routing/error-handling):

0 commit comments

Comments
 (0)