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>>[]Requiredrouters
Record<string, Router[]>RequiredMethods
addRouter
Parameters
path
stringRequiredrouter
RouterRequiredReturns
void
voidRequiredgetRouters
Parameters
path
stringRequiredReturns
Router[]
Router[]RequiredvalidateMiddleware_
Validates a middleware function, throws if fn is not of type function.
Parameters
fn
unknownRequiredthe middleware function to validate.
Returns
void
voidRequirednothing if the middleware is a function
addPostAuthentication
Adds a middleware function to be called after authentication is completed.
Parameters
middleware
middlewareHandlerTypeRequiredthe middleware function. Should return a
middleware function.
options
Record<string, unknown>Requiredthe arguments that will be passed to the
middleware
Returns
void
voidRequiredvoid
addPreAuthentication
Adds a middleware function to be called before authentication is completed.
Parameters
middleware
middlewareHandlerTypeRequiredthe middleware function. Should return a
middleware function.
options
Record<string, unknown>Requiredthe arguments that will be passed to the
middleware
Returns
void
voidRequiredvoid
addPreCartCreation
Adds a middleware function to be called before cart creation
Parameters
middleware
RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>Requiredthe middleware function. Should return a
middleware function.
Returns
void
voidRequiredAdds a middleware function to be called before cart creation
usePostAuthentication
Adds post authentication middleware to an express app.
Parameters
app
RouterRequiredthe express app to add the middleware to
Returns
void
voidRequiredAdds post authentication middleware to an express app.
usePreAuthentication
Adds pre authentication middleware to an express app.
Parameters
app
RouterRequiredthe express app to add the middleware to
Returns
void
voidRequiredAdds 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?