Skip to main content

Class: MiddlewareService

Orchestrates dynamic middleware registered through the Medusa Middleware API

Constructors

constructor

new MiddlewareService(container)

Parameters

NameType
containerany

Defined in

services/middleware.js:7

Properties

postAuthentication_

postAuthentication_: any[]

Defined in

services/middleware.js:8


preAuthentication_

preAuthentication_: any[]

Defined in

services/middleware.js:9


preCartCreation_

preCartCreation_: any[]

Defined in

services/middleware.js:10


routers

routers: Object

Defined in

services/middleware.js:11

Methods

addPostAuthentication

addPostAuthentication(middleware, options): void

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

Parameters

NameTypeDescription
middlewareFunctionthe middleware function. Should return a middleware function.
optionsanythe arguments that will be passed to the middleware

Returns

void

Defined in

services/middleware.js:45


addPreAuthentication

addPreAuthentication(middleware, options): void

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

Parameters

NameTypeDescription
middlewareFunctionthe middleware function. Should return a middleware function.
optionsanythe arguments that will be passed to the middleware

Returns

void

Defined in

services/middleware.js:61


addPreCartCreation

addPreCartCreation(middleware): void

Adds a middleware function to be called before cart creation

Parameters

NameTypeDescription
middlewareFunctionthe middleware function. Should return a middleware function.

Returns

void

Defined in

services/middleware.js:75


addRouter

addRouter(path, router): void

Parameters

NameType
pathany
routerany

Returns

void

Defined in

services/middleware.js:14


getRouters

getRouters(path): any

Parameters

NameType
pathany

Returns

any

Defined in

services/middleware.js:19


usePostAuthentication

usePostAuthentication(app): void

Adds post authentication middleware to an express app.

Parameters

NameTypeDescription
appExpressAppthe express app to add the middleware to

Returns

void

Defined in

services/middleware.js:85


usePreAuthentication

usePreAuthentication(app): void

Adds pre authentication middleware to an express app.

Parameters

NameTypeDescription
appExpressAppthe express app to add the middleware to

Returns

void

Defined in

services/middleware.js:96


usePreCartCreation

usePreCartCreation(): any[]

Returns

any[]

Defined in

services/middleware.js:102


validateMiddleware_

validateMiddleware_(fn): void

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

Parameters

NameTypeDescription
fnFunctionthe middleware function to validate.

Returns

void

Defined in

services/middleware.js:28