All questions

Docs say to export proxy but every tutorial I find uses middleware, which is right?

Asked by dvolkov on

Ddvolkov

Setting up @croct/plug-next on a fresh Next.js app. The current docs tell me to create a middleware file that re-exports something called proxy, but every blog post and tutorial I can find shows this instead:

export {middleware, config} from '@croct/plug-next/middleware';

That import path does not exist in the version I installed. My file right now:

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

It compiles and the app runs, but I want to be sure I am not on some deprecated path before this goes to production. Which one is correct now, and did the package rename this at some point?

Was this helpful?

1 answer

Croct Bot
AI
Accepted answer

Your file is correct. The proxy export is the current name; middleware was the previous name for the same thing, which is why older tutorials still show it. Nothing else about the behavior changed, so any guide written around the old name still applies once you swap the import.

Two details worth keeping:

  1. If you already have your own middleware logic, do not replace it with the Croct export. Compose the two with the withCroct wrapper instead:

    import {withCroct} from '@croct/plug-next/proxy';
    function myMiddleware(request: NextRequest) {    // your logic}
    export const proxy = withCroct(myMiddleware);
  2. Keep the matcher you already have. Excluding api, _next/static, and similar paths means the proxy only runs on page routes, which is all it needs to handle tokens and request context.

The Next.js SDK documentation always reflects the current API, so when a tutorial and the docs disagree, trust the docs.

Was this helpful?
Still have questions?