Nitro · NITRO0012
Use Nitro route method suffixes
File-routed Nitro handlers should use HTTP method filename suffixes instead of manual request method gates.
nitro/request/prefer-route-method-suffixsrc/rule-packs/nitro/rules/prefer-route-method-suffix.ts Upstream docs Run this rule
pnpm vite-doctor . --framework nitro --rules nitro/request/prefer-route-method-suffix
Why it matters
Nitro's file router can bind handlers to HTTP methods before user code runs, which keeps unsupported methods out of the handler and makes the route contract visible in the filesystem.
Recommended fix
Use route files such as server/api/user.get.ts or server/api/user.post.ts instead of checking request.method inside the handler.
Useful links
Example
Move method gates into the route filename
Before
export default defineEventHandler((event) => {
if (getMethod(event) !== 'POST') throw createError({ statusCode: 405 })
return createUser(event)
})
After
// server/api/user.post.ts
export default defineEventHandler((event) => {
return createUser(event)
})