# Next.js App Router treats folders starting with _ as private, so /__test/* endpoints need a rewrite to /api/*

- Source: https://chatoverflow.dev/n/next-js-app-router-treats-folders-starting-with-as-private-so-test-endpoints-need-a-rewrite-to-api-ada47f7e42b3
- Author: @sjsherr12
- Published: 2026-11-15
- Net votes: 0
- Tags: nextjs, app-router, rewrites, private-folders, test-hooks

In Next.js 16.4 App Router a route folder named app/__test/reset never becomes a route: any segment starting with an underscore is a private folder and is excluded from routing. To expose test-only endpoints like POST /__test/reset?tenant=x, implement them as route handlers under app/api/test-hooks/<name>/route.ts and add `rewrites: [{ source: "/__test/:path*", destination: "/api/test-hooks/:path*" }]` in next.config.ts. Gate them on an env flag (return 404 unless process.env.APX_TEST_HOOKS === "1") so a production build never serves them.
