Skip to main content

Running your own

The app is Next.js on Vercel, MongoDB Atlas, Auth.js with Google, Stripe, and Anthropic. Nothing here is required to use rewr.it — this is for running it.

Local

npm install
cp .env.example .env.local
npm run dev

Then, once against a fresh database:

npm run db:indexes

Environment

VariablePurpose
ANTHROPIC_API_KEYServer-only rewrite key
ANTHROPIC_MODEL_STANDARD / ANTHROPIC_MODEL_FASTModel ids behind the product's tiers
MONGODB_URIAtlas connection string
AUTH_SECRETAuth.js secret
AUTH_GOOGLE_ID / AUTH_GOOGLE_SECRETGoogle OAuth
DEVICE_COOKIE_SECRETSigns the anonymous device cookie
STRIPE_SECRET_KEY / STRIPE_WEBHOOK_SECRET / STRIPE_PRICE_PROBilling and the Pro subscription
STRIPE_PRICE_CREDITS_MINI / _STARTER / _POPULAR / _POWEROne-time credit lots
STRIPE_AUTOMATIC_TAXTurn on only after Tax is set up and registrations are active
NEXT_PUBLIC_APP_URLCanonical site URL. Checkout and Portal returns, CORS, and metadataBase
DAILY_SPEND_CAP_USDApp-wide daily spend breaker. Default 50
CRON_SECRETBearer token for /api/cron/reconcile
HUMANIZE_DISABLEDKill switch. true makes the rewrite endpoint return 503
DETECT_DISABLEDSame, for /api/detect
HUMANIZER_EXTENSION_IDSComma-separated extension ids allowed through CORS in production
HUMANIZER_CORS_ORIGINSExtra allowed origins, comma-separated
ADMIN_EMAILSAllowlist for /admin. Unset disables admin entirely
UNLIMITED_EMAILSAccounts whose period caps are lifted. Word caps and the spend cap still apply
NEXT_PUBLIC_LEGAL_ENTITYEntity named on /terms and /privacy
NEXT_PUBLIC_LEGAL_JURISDICTIONGoverning law for /terms
NEXT_PUBLIC_LEGAL_CONTACT_EMAILWhere legal and privacy requests go
NEXT_PUBLIC_APP_URL

Next resolves every Open Graph URL against metadataBase, which comes from this. A production build still pointing at localhost has broken link previews everywhere and nothing that says so.

The switches that matter under load

  • DAILY_SPEND_CAP_USD — a breaker, not a budget. When it trips, rewrites return 503 with code: "spend_cap" and no request reaches Anthropic.
  • HUMANIZE_DISABLED — the kill switch. 503, code: "kill_switch", instantly, for everyone.
  • Per-plan concurrency and burst limits live in lib/plans.ts, not in env. They are code because they are entitlements.

The tell policy

Thresholds, vocabulary, and pattern rules are editable at /admin/policy and served to clients by GET /api/policy. Clients ship with the defaults, so the detector works before the fetch lands and keeps working if it fails.

Changing the policy changes what every client flags and what the score means. There is one copy for exactly that reason.

These docs

The documentation site is a Docusaurus build in docs-site/, separate from the Next app — separate package.json, separate build, no shared imports.

cd docs-site
npm install
npm start # dev server
npm run build # static site into docs-site/build

The look comes from docs-site/src/css/custom.css, which mirrors the tokens in docs/BRAND.md. If a colour or a face changes, it changes in the brand doc and in lib/theme.ts first, and this stylesheet follows.