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
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
voidvoid
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
voidvoid
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
voidaddRouter
Parameters
path
stringRequiredrouter
RouterRequiredReturns
void
voidgetRouters
Parameters
path
stringRequiredReturns
Router[]
Router[]RequiredusePostAuthentication
Adds post authentication middleware to an express app.
Parameters
app
RouterRequiredthe express app to add the middleware to
Returns
void
voidusePreAuthentication
Adds pre authentication middleware to an express app.
Parameters
app
RouterRequiredthe express app to add the middleware to
Returns
void
voidusePreCartCreation
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
fn
unknownRequiredthe middleware function to validate.
Returns
void
voidnothing if the middleware is a function
Was this section helpful?