Page Contents

Home > @loopback/rest > RestApplication > expressMiddleware

RestApplication.expressMiddleware() method

Bind an Express middleware to this server context

Signature:

expressMiddleware(key: BindingAddress, middleware: ExpressRequestHandler | ExpressRequestHandler[], options?: MiddlewareBindingOptions): Binding<Middleware>;

Parameters

Parameter Type Description
key BindingAddress Middleware binding key
middleware ExpressRequestHandler | ExpressRequestHandler[] Express middleware handler function(s)
options MiddlewareBindingOptions (Optional)

Returns:

Binding<Middleware>

Example

import myExpressMiddlewareFactory from 'my-express-middleware';
const myExpressMiddlewareConfig= {};
const myExpressMiddleware = myExpressMiddlewareFactory(myExpressMiddlewareConfig);
server.expressMiddleware('middleware.express.my', myExpressMiddleware);