Allowed Methods Restricter


This middleware works by default for * HTTP Methods and will throw an 405 Method Not Allowed error when the there will be a request sent with an HTTP Method that is not allowed.

It will help you solve this security problem.

export type HTTPMethod = 'GET' | 'POST' | 'DELETE' | 'PATCH' | 'POST' | string;export type AllowedHTTPMethods = HTTPMethod[] | '*'

To write a custom logic for this middleware follow this pattern:

nuxt.config.ts
export default defineNuxtConfig({  security: {    allowedMethodsRestricter: ['POST'],  }})

Or use routeRules for per route configuration:

nuxt.config.ts
export default defineNuxtConfig({  routeRules: {    '/my-secret-route': {      security: {        allowedMethodsRestricter: ['POST'],      }    }  }