Skip to content

Commit

Permalink
docs: add middleware tunneling to README
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielelpidio committed Jan 8, 2025
1 parent 4005dc8 commit 1484a02
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,26 @@ For example, to send all logs except for debug logs to Axiom:
export NEXT_PUBLIC_AXIOM_LOG_LEVEL=info
```
## Middleware tunneling (beta)
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.
To enable this feature, in your middleware.ts file, add the following code:
```ts
import { axiomMiddleware } from 'next-axiom';

export const middleware = axiomMiddleware();

export const config = {
matcher: '/_axiom/:path*', // Makes it so that the middleware only fires for requests that match this path
};
```
and in your environment variables, change the `NEXT_PUBLIC_AXIOM_TOKEN` to `AXIOM_TOKEN`.
This will proxy all requests to `/_axiom/logs` and `/_axiom/web-vitals` to Axiom using the middleware as a proxy layer.
## Capture errors
To capture routing errors, use the [error handling mechanism of Next.js](https://nextjs.org/docs/app/building-your-application/routing/error-handling):
Expand Down

0 comments on commit 1484a02

Please sign in to comment.