Generated the following references: - `entities` - `file` - `fulfillment` - `inventory` - `js_client` - `medusa` - `medusa_config` - `medusa_react` - `modules` - `notification` - `payment` - `price_selection` - `pricing` - `product` - `search` - `services` - `stock_location` - `tax` - `tax_calculation` - `types` - `workflows` Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
120 lines
6.2 KiB
Plaintext
120 lines
6.2 KiB
Plaintext
---
|
|
displayed_sidebar: servicesSidebar
|
|
---
|
|
|
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
|
|
|
# MiddlewareService
|
|
|
|
Orchestrates dynamic middleware registered through the Medusa Middleware API
|
|
|
|
## constructor
|
|
|
|
___
|
|
|
|
## Properties
|
|
|
|
<ParameterTypes parameters={[{"name":"postAuthentication_","type":"`middlewareType`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"preAuthentication_","type":"`middlewareType`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"preCartCreation_","type":"RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"routers","type":"`Record<string, Router[]>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="MiddlewareService"/>
|
|
|
|
___
|
|
|
|
## Methods
|
|
|
|
### addRouter
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"path","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"router","type":"`Router`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addRouter"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="addRouter"/>
|
|
|
|
### getRouters
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"path","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="getRouters"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"Router[]","type":"`Router`[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="getRouters"/>
|
|
|
|
### validateMiddleware\_
|
|
|
|
Validates a middleware function, throws if fn is not of type function.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"fn","type":"`unknown`","description":"the middleware function to validate.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="validateMiddleware_"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"nothing if the middleware is a function","expandable":false,"children":[]}]} sectionTitle="validateMiddleware_"/>
|
|
|
|
### addPostAuthentication
|
|
|
|
Adds a middleware function to be called after authentication is completed.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"middleware","type":"`middlewareHandlerType`","description":"the middleware function. Should return a\n middleware function.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`Record<string, unknown>`","description":"the arguments that will be passed to the\n middleware","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addPostAuthentication"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"void","expandable":false,"children":[]}]} sectionTitle="addPostAuthentication"/>
|
|
|
|
### addPreAuthentication
|
|
|
|
Adds a middleware function to be called before authentication is completed.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"middleware","type":"`middlewareHandlerType`","description":"the middleware function. Should return a\n middleware function.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`Record<string, unknown>`","description":"the arguments that will be passed to the\n middleware","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addPreAuthentication"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"void","expandable":false,"children":[]}]} sectionTitle="addPreAuthentication"/>
|
|
|
|
### addPreCartCreation
|
|
|
|
Adds a middleware function to be called before cart creation
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"middleware","type":"RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>","description":"the middleware function. Should return a\n middleware function.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addPreCartCreation"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Adds a middleware function to be called before cart creation","expandable":false,"children":[]}]} sectionTitle="addPreCartCreation"/>
|
|
|
|
### usePostAuthentication
|
|
|
|
Adds post authentication middleware to an express app.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"app","type":"`Router`","description":"the express app to add the middleware to","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="usePostAuthentication"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Adds post authentication middleware to an express app.","expandable":false,"children":[]}]} sectionTitle="usePostAuthentication"/>
|
|
|
|
### usePreAuthentication
|
|
|
|
Adds pre authentication middleware to an express app.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"app","type":"`Router`","description":"the express app to add the middleware to","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="usePreAuthentication"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Adds pre authentication middleware to an express app.","expandable":false,"children":[]}]} sectionTitle="usePreAuthentication"/>
|
|
|
|
### usePreCartCreation
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]","type":"RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="usePreCartCreation"/>
|