Middleware
Request Size Limiter
Limit the maximum size of requests to avoid overloading.
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.
Read more about setting request size limits here.
Usage
This middleware is enabled globally by default. You can customize it both globally and per route like following:
nuxt.config.ts
export default defineNuxtConfig({
// Global
security: {
requestSizeLimiter: {
// options
}
}
// Per Route
routeRules: {
'/my-secret-route': {
security: {
requestSizeLimiter: {
// options
}
}
}
}
})
You can also disable the middleware globally or per route by setting requestSizeLimiter: false
.
Options
Request size limiter accepts following configuration options:
type RequestSizeLimiter = {
maxRequestSizeInBytes: number;
maxUploadFileRequestInBytes: number;
throwError: boolean;
};
maxRequestSizeInBytes
- Default:
2000000
Maximum size of the normal request in bytes.
maxUploadFileRequestInBytes
- Default:
8000000
Maximum size of the upload file request in bytes.
throwError
- Default:
true
Whether to throw Nuxt Error with appriopriate error code and message. If set to false, it will just return the object with the error that you can handle.