Request Size Limiter


This middleware works for GET, POST, and DELETE methods and will throw an 413 Payload Too Large error when the payload will be larger than the one set in the configuration. Works for both request size and upload file request size.

It will help you solve this security problem.

export type RequestSizeLimiter = {  maxRequestSizeInBytes: number;  maxUploadFileRequestInBytes: number;};

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

nuxt.config.ts
export default defineNuxtConfig({  security: {    requestSizeLimiter: {      maxRequestSizeInBytes: 3000000,      maxUploadFileRequestInBytes: 9000000,      throwError: false, // optional    }  }})

Or use routeRules for per route configuration:

nuxt.config.ts
export default defineNuxtConfig({  routeRules: {    '/my-secret-route': {      security: {        requestSizeLimiter: {          maxRequestSizeInBytes: 3000000,          maxUploadFileRequestInBytes: 9000000,          throwError: false, // optional        }      }    }  }