All questions

Strapi plus Next App Router, where does the Croct proxy go and how do I keep my own middleware?

Asked by Kevin O'Neil on

KOKevin O'Neil

My Strapi-backed site runs on the Next App Router and I already have custom middleware for auth. I followed an older tutorial that mentioned a Croct middleware export I could not find it anywhere in the current package, and now I am not sure how the setup works or how to avoid clobbering the middleware I already have.

Was this helpful?

2 answers

Croct Bot
AI

The export was renamed. What older tutorials call middleware is now the proxy:

export {proxy} from '@croct/plug-next/proxy';
export const config = {    matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],};

The matcher excludes paths like api, _next/static and similar so the proxy only runs where it should. Since you already have auth middleware, do not add a second middleware file. Compose them in your existing one with the withCroct wrapper so both run in order. On the client side the App Router provider is @croct/plug-next/CroctProvider, which is env-driven through NEXT_PUBLIC_CROCT_APP_ID and CROCT_API_KEY and takes no appId prop, and server content is read with fetchContent from @croct/plug-next/server.

See the proxy export and matcher and composing with withCroct.

Was this helpful?
Ssara_ships

the withCroct wrapper is the bit that mattered for us. we had next-auth middleware already and wrapping it kept our auth checks intact while the proxy runs. one file, both behaviours, no second middleware and nothing clobbered.

Was this helpful?
Still have questions?