MiddlewareService
Orchestrates dynamic middleware registered through the Medusa Middleware API
constructor
Properties
postAuthentication_middlewareType[]RequiredpreAuthentication_middlewareType[]RequiredpreCartCreation_RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequiredroutersRecord<string, Router[]>RequiredMethods
addPostAuthentication
Adds a middleware function to be called after authentication is completed.
Parameters
middlewaremiddlewareHandlerTypeRequiredthe middleware function. Should return a
middleware function.
optionsRecord<string, unknown>Requiredthe arguments that will be passed to the
middleware
Returns
voidvoidRequiredvoid
addPreAuthentication
Adds a middleware function to be called before authentication is completed.
Parameters
middlewaremiddlewareHandlerTypeRequiredthe middleware function. Should return a
middleware function.
optionsRecord<string, unknown>Requiredthe arguments that will be passed to the
middleware
Returns
voidvoidRequiredvoid
addPreCartCreation
Adds a middleware function to be called before cart creation
Parameters
middlewareRequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>Requiredthe middleware function. Should return a
middleware function.
Returns
voidvoidRequiredaddRouter
Parameters
pathstringRequiredrouterRouterRequiredReturns
voidvoidRequiredgetRouters
Parameters
pathstringRequiredReturns
Router[]Router[]RequiredusePostAuthentication
Adds post authentication middleware to an express app.
Parameters
appRouterRequiredthe express app to add the middleware to
Returns
voidvoidRequiredusePreAuthentication
Adds pre authentication middleware to an express app.
Parameters
appRouterRequiredthe express app to add the middleware to
Returns
voidvoidRequiredusePreCartCreation
Returns
RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequiredvalidateMiddleware_
Validates a middleware function, throws if fn is not of type function.
Parameters
fnunknownRequiredthe middleware function to validate.
Returns
voidvoidRequirednothing if the middleware is a function
Was this section helpful?