Page Contents
express package
The Express integration package for loopback-next.
Remarks
This module introduces Koa style cascading middleware that leverage async/await. It also enables the ability to plug in existing Express middleware as LoopBack middleware or interceptors so that they can be used at sequence/action, global interceptor, and local interceptor tiers.
This module also serves as a standalone extension to Express to provide extensibility and composability for large-scale Express applications by leveraging LoopBack’s Dependency Injection and Extension Point/Extension pattern.
Classes
| Class | Description |
|---|---|
| BaseMiddlewareRegistry | Base Context that provides APIs to register middleware |
| ExpressApplication | A LoopBack application with Express server |
| ExpressMiddlewareInterceptorProvider | Base class for MiddlewareInterceptor provider classes |
| ExpressServer | An Express server that provides middleware composition and injection |
| InvokeMiddlewareProvider | Extension point for middleware to be run as part of the sequence actions |
| MiddlewareChain | An interceptor chain of middleware. This represents a list of cascading middleware functions to be executed by the order of group names. |
| MiddlewareContext | A per-request Context for middleware to combine an IoC container with handler context (request, response, etc.). |
| MiddlewareView | Watch middleware binding keys for the given context and sort them by group |
Functions
| Function | Description |
|---|---|
| asMiddleware(options) | Template function for middleware bindings |
| buildName(middlewareFactory, providedName, suffix) | Build a name for the middleware |
| createInterceptor(middlewareFactory, middlewareConfig) | Create an interceptor function from express middleware. |
| createMiddleware(middlewareFactory, middlewareConfig) | An adapter function to create a LoopBack middleware from Express middleware factory function and configuration object. |
| createMiddlewareBinding(middlewareProviderClass, options) | Create a binding for the middleware provider class |
| createMiddlewareInterceptorBinding(middlewareProviderClass, options) | Create a binding for the middleware based interceptor |
| defineInterceptorProvider(middlewareFactory, defaultMiddlewareConfig, options) | Define a provider class that wraps the middleware as an interceptor |
| executeExpressRequestHandler(handler, request, response) | Execute an Express-style callback-based request handler. |
| getMiddlewareContext(request) | A helper function to retrieve the MiddlewareContext/RequestContext from the request object |
| invokeExpressMiddleware(middlewareCtx, handlers) | Invoke a list of Express middleware handler functions |
| invokeMiddleware(middlewareCtx, options) | Discover and invoke registered middleware in a chain for the given extension point. |
| MiddlewareMixin(superClass) | |
| registerExpressMiddleware(ctx, middlewareFactory, middlewareConfig, options) | Bind a Express middleware to the given context |
| registerExpressMiddlewareInterceptor(ctx, middlewareFactory, middlewareConfig, options) | Bind a middleware interceptor to the given context |
| registerMiddleware(ctx, middleware, options) | Bind the middleware function or provider class to the context |
| sortListOfGroups(orderedGroups) | Sort the groups by their relative order |
| toExpressMiddleware(ctx) | An adapter function to create an Express middleware handler to discover and invoke registered LoopBack-style middleware in the context. |
| toInterceptor(firstHandler, additionalHandlers) | Wrap an express middleware handler function as an interceptor |
| toMiddleware(firstHandler, additionalHandlers) | An adapter function to create a LoopBack middleware that invokes the list of Express middleware handler functions in the order of their positions |
Interfaces
| Interface | Description |
|---|---|
| BaseMiddlewareBindingOptions | Options to create a middleware binding for the sequence action or interceptor. |
| ExpressMiddlewareFactory | Interface for an express middleware factory |
| HandlerContext | An object holding HTTP request, response and other data needed to handle an incoming HTTP request. |
| InvokeMiddleware | Interface for the invoker of middleware registered under the an extension point name. |
| InvokeMiddlewareOptions | Options for InvokeMiddleware |
| Middleware | Interface LoopBack 4 middleware to be executed within sequence of actions. A middleware for LoopBack is basically a generic interceptor that uses MiddlewareContext. |
| MiddlewareBindingOptions | Options to bind middleware as a request context based interceptor within an InvokeMiddleware action of the sequence. |
| MiddlewareCreationOptions | Options for defining a middleware |
| MiddlewareInterceptorBindingOptions | Options to bind a middleware as an interceptor to the context |
| MiddlewareRegistry | A context that allows middleware registration |
Namespaces
| Namespace | Description |
|---|---|
| MiddlewareBindings | |
| MiddlewareGroups | Constants for middleware groups |
Variables
| Variable | Description |
|---|---|
| DEFAULT_MIDDLEWARE_CHAIN | Default extension point name for middleware |
| DEFAULT_MIDDLEWARE_GROUP | Default order group name for Express middleware based global interceptors |
| GLOBAL_MIDDLEWARE_INTERCEPTOR_NAMESPACE | Default namespace for Express middleware based global interceptors |
| MIDDLEWARE_CONTEXT | A symbol to store MiddlewareContext on the request object. This symbol can be referenced by name, before it is created. |
| MIDDLEWARE_INTERCEPTOR_NAMESPACE | Default namespace for Express middleware based local interceptors |
| MIDDLEWARE_NAMESPACE | Default namespaces for middleware |
Type Aliases
| Type Alias | Description |
|---|---|
| ExpressRequestHandler | Type alias for Express RequestHandler |
| ExpressServerConfig | Configuration for a LoopBack based Express server |
| MiddlewareOrKey | A middleware function or binding key |