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
addRouter
Parameters
pathstringRequiredrouterRouterRequiredReturns
voidvoidRequiredgetRouters
Parameters
pathstringRequiredReturns
Router[]Router[]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
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
voidvoidRequiredAdds a middleware function to be called before cart creation
usePostAuthentication
Adds post authentication middleware to an express app.
Parameters
appRouterRequiredthe express app to add the middleware to
Returns
voidvoidRequiredAdds post authentication middleware to an express app.
usePreAuthentication
Adds pre authentication middleware to an express app.
Parameters
appRouterRequiredthe express app to add the middleware to
Returns
voidvoidRequiredAdds pre authentication middleware to an express app.
usePreCartCreation
Returns
RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]RequiredWas this section helpful?