# proxy

Learn how to handle SDK logic between client and server.

This function handles the SDK logic between the client and the server. It is equivalent to calling [`withCroct`](with-croct) with no arguments.

> **Next.js 15 and earlier**
>
> Next.js 16 [renamed](https://nextjs.org/docs/app/api-reference/file-conventions/proxy#migration-to-proxy) the `middleware` file convention to `proxy`. Select the tab matching your Next.js version in the example below.

## Signature

This function has the following signature:

```ts
function proxy(request: NextRequest, event: NextFetchEvent) => NextProxyResult | Promise<NextProxyResult>
```

## Example

Here is an example of how to use this proxy:

**Next ≤ 15 — JavaScript**

```js
export {middleware} from '@croct/plug-next/middleware';

export const config = {
  matcher: "/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)"
};
```

**Next ≤ 15 — TypeScript**

```ts
export {middleware} from '@croct/plug-next/middleware';

export const config = {
  matcher: "/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)"
};
```

**Next ≥ 16 — JavaScript**

```js
export {proxy} from '@croct/plug-next/proxy';

export const config = {
  matcher: "/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)"
};
```

**Next ≥ 16 — TypeScript**

```ts
export {proxy} from '@croct/plug-next/proxy';

export const config = {
  matcher: "/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)"
};
```

The `config` constant is a convenience export defining a [matcher](https://nextjs.org/docs/app/api-reference/file-conventions/proxy#matcher) that targets only page routes, excluding API routes, static assets, and other non-page resources such as images and the favicon.

The constant is defined as follows:

```ts
export const config = {
  matcher: [
  /*
   * Match all request paths except for the ones starting with:
   * - api (API routes)
   * - _next/static (static files)
   * - _next/image (image optimization files)
   * - favicon.ico (favicon file)
   */
    '^(?!/(api|_next/static|_next/image|favicon.ico)).*',
  ],
};
```
