All questions

Will npx croct init clobber anything in an existing Next.js repo?

Asked by cfraser on

Ccfraser

Before I run any CLI scaffolding tool on a mature codebase, I like to know exactly what it intends to touch. Our Next.js repo is three years old, has a carefully composed middleware.ts (auth plus locale detection), and a strict review process.

So, for npx croct@latest init on an existing app:

  1. Which files does it create or modify?
  2. Does it try to write a middleware file, and what happens to the one we already have?
  3. How do I verify the integration actually works before merging the branch?

I will read the diff regardless, just want to know what to expect in it.

Was this helpful?

1 answer

YyusufdAccepted answer

Ran this on a similarly aged repo recently, so here is the concrete inventory. The CLI detects your framework and wires the SDK; on Next.js the diff contains:

  • The @croct/plug-next dependency in package.json.
  • The provider added to your layout.
  • A proxy export (Croct's middleware is called proxy) with a matcher that excludes api, _next/static, and similar paths.
  • Env vars: NEXT_PUBLIC_CROCT_APP_ID and CROCT_API_KEY.
  • A croct.json5 config file and generated slots.d.ts types.

On your question 2, this is the one spot that needs your judgment rather than the generator's. Do not let a plain proxy export replace your existing middleware. Compose them instead:

import {withCroct} from '@croct/plug-next/proxy';import {middleware as existing} from './lib/middleware';
export const proxy = withCroct(existing);

Your auth and locale logic keeps running, Croct wraps around it. Review that file most carefully, the rest of the diff is routine codegen.

For verification before merging: run the branch, browse a few pages, then check the Integration page in the Croct dashboard. It shows a green "Received traffic in the past 24 hours" badge once requests flow. Green badge plus a clean diff review and you are done.

Was this helpful?
Ccfraser

Ran it on a branch. The diff matched your inventory exactly, and the withCroct composition preserved our middleware chain. Badge went green. Merging. Thanks for the precise answer.

Still have questions?