Build-time route check
How the build finds routes that forgot defineBffHandler.
When Nitro starts a build, the module reads every route file matched by routePatterns and parses it with the TypeScript compiler. Each file must:
- import
defineBffHandlerfrom#bff-guard(a renamed import is fine), and export defaulta direct call of it.
Otherwise the build fails:
[bffGuard] Route coverage check failed. Import defineBffHandler from #bff-guard and call it in the default export:
- server/api/forgotten.get.ts
Accepted and rejected
// ✅ accepted
import { defineBffHandler } from '#bff-guard'
export default defineBffHandler(handler)
// ✅ accepted: renamed import
import { defineBffHandler as guard } from '#bff-guard'
export default guard(handler, { access: 'public' })
// ❌ rejected: re-export from another file
export { default } from './orders'
// ❌ rejected: wrapper or variable in between
const handler = defineBffHandler(listOrders)
export default handler
// ❌ rejected: a function with the same name from somewhere else
import { defineBffHandler } from '~/server/utils/guard'
export default defineBffHandler(handler)
The rule is strict on purpose: a reviewer can see the protection on the route file itself.
Choosing the patterns
The default is ['server/api/**'], which follows Nitro's apiDir if you renamed it. To also check other folders, list them all. Your array replaces the default.
nuxt.config.ts
bffGuard: {
verifyUser: './server/auth/verify-user.ts',
routePatterns: ['server/api/**', 'server/routes/private/**'],
}
Each pattern starts with server/ and applies to every Nitro scan directory, including layers. Negative patterns (!) are not allowed. Keep helpers outside the checked folders, for example in server/utils/.
What the check cannot see
- Handlers registered in
nitro.handlersinnuxt.config.ts. - Handlers that other modules add with
addServerHandler. - Routes outside your patterns, such as
server/routes/**by default. - Routes added while
nuxt devis running. Restart, or rely on the production build.
Wrap such handlers in defineBffHandler yourself and review them.