Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
bodyLimit()
Reject oversized request bodies before they reach your handler, with 413 Payload Too Large.
Use case
An unbounded request body is a denial-of-service vector: a single client can stream megabytes (or gigabytes) to exhaust memory. A body cap rejects anything over a sane size early, so your handlers only ever see payloads you are willing to process.
How it works
It checks the actual buffered body size, not just the Content-Length header, so a missing or lying
length cannot bypass it. If the body exceeds max, it replies 413 Payload Too Large and stops; otherwise
it calls next().
Configuration
| Option | Default | Notes |
|---|---|---|
max | 1048576 (1 MB) | Max body bytes. |
Example
Notes
Set a small global cap and raise it per-route for the few endpoints that need it (uploads), rather than a large global cap. The runtime's native
maxBodySize(oncreateApp) is the hard backstop beneath this middleware.
Next: validateContentType.