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 no arguments.
Next.js 15 and earlier
Next.js 16 renamed 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:
function proxy(request: NextRequest, event: NextFetchEvent) => NextProxyResult | Promise<NextProxyResult>Example
Here is an example of how to use this proxy:
proxy.js
Next ≥ 16
JavaScript
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 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:
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)).*', ],};