docs: updated API Routes and Middlewares docs (#5588)
* docs: updated API Routes and Middlewares docs * fix eslint errors
This commit is contained in:
@@ -53,10 +53,19 @@ Middlewares are used to perform an action when a request is sent to an API Route
|
||||
|
||||
Middlewares are defined in the `src/api/middlewares.ts` file. This file must expose a config object of type `MiddlewaresConfig` imported from `@medusajs/medusa`.
|
||||
|
||||
This object accepts a parameter `routes`, whose value is an array of middleware route objects. Each middleware route object accepts the following properties:
|
||||
This object accepts two parameters:
|
||||
|
||||
- The `matcher` property accepts a string or a regular expression that will be used to check whether the middlewares should be applied on a API Routes.
|
||||
- The `middlewares` property is an array of middlewares that should be applied on API Routes matching the pattern specified in `matcher`.
|
||||
- `routes`: an array of middleware route objects. Each middleware route object accepts the following properties:
|
||||
- `matcher`: a string or a regular expression that will be used to check whether the middlewares should be applied on a API Routes.
|
||||
- `middlewares`: an array of middlewares that should be applied on API Routes matching the pattern specified in `matcher`.
|
||||
- `method`: a string or an array of strings, where each value is the name of an HTTP method. This allows you to apply the middlewares only on the specified HTTP methods in this property. If not specified, the middlewares are applied on all HTTP methods.
|
||||
- `bodyParser`: This property can have two types of values:
|
||||
- `false`: If this value is used, the default `json` body parser middleware is disabled. This allows you to override the body parser with your own middleware. For example, it's useful when changing the [default parser for webhooks](./create.mdx#parse-request-body-parameters).
|
||||
- `object`: You can pass an object with configurations for the default `json` body parser middleware. It accepts the following configurations:
|
||||
- `sizeLimit`: A number indicating the maximum body size allowed in bytes. By default, it's `1000` bytes. If a request body is greater than that, an error will be thrown. So, you can set this configuration if you expect the request body size of an API route to be greater than `1000` bytes.
|
||||
- `errorHandler`: This property can have two types of values:
|
||||
- `false`: If this value is used, the default error handler is disabled. Learn more about its behavior [here](./create.mdx#disable-default-error-handler).
|
||||
- `function`: A middleware function used to define a new error handler. Learn more [here](./create.mdx#override-error-handler).
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user