Skip to main content
Skip to main content

MiddlewareService

internal.internal.MiddlewareService

Orchestrates dynamic middleware registered through the Medusa Middleware API

Properties

postAuthentication_middlewareType[]Required
preAuthentication_middlewareType[]Required
preCartCreation_RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]Required
routersRecord<string, Router[]>Required

Methods

addPostAuthentication

addPostAuthentication(middleware, options): void

Adds a middleware function to be called after authentication is completed.

Parameters

middlewaremiddlewareHandlerTypeRequired
the middleware function. Should return a middleware function.
optionsRecord<string, unknown>Required
the arguments that will be passed to the middleware

Returns

void

voidvoid
void

addPreAuthentication

addPreAuthentication(middleware, options): void

Adds a middleware function to be called before authentication is completed.

Parameters

middlewaremiddlewareHandlerTypeRequired
the middleware function. Should return a middleware function.
optionsRecord<string, unknown>Required
the arguments that will be passed to the middleware

Returns

void

voidvoid
void

addPreCartCreation

addPreCartCreation(middleware): void

Adds a middleware function to be called before cart creation

Parameters

middlewareRequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>Required
the middleware function. Should return a middleware function.

Returns

void

voidvoid

addRouter

addRouter(path, router): void

Parameters

pathstringRequired
routerRouterRequired

Returns

void

voidvoid

getRouters

getRouters(path): Router[]

Parameters

pathstringRequired

Returns

Router[]

Router[]Router[]Required

usePostAuthentication

usePostAuthentication(app): void

Adds post authentication middleware to an express app.

Parameters

appRouterRequired
the express app to add the middleware to

Returns

void

voidvoid

usePreAuthentication

usePreAuthentication(app): void

Adds pre authentication middleware to an express app.

Parameters

appRouterRequired
the express app to add the middleware to

Returns

void

voidvoid

usePreCartCreation

usePreCartCreation(): RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]

Returns

RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]

RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any\>\>[]RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]Required

validateMiddleware_

validateMiddleware_(fn): void

Validates a middleware function, throws if fn is not of type function.

Parameters

fnunknownRequired
the middleware function to validate.

Returns

void

voidvoid
nothing if the middleware is a function
Was this section helpful?