@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
105 lines (93 loc) • 17.2 kB
Markdown
---
lang: en
title: 'API docs: express.middlewaremixin'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/express
permalink: /doc/en/lb4/apidocs.express.middlewaremixin.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/express](./express.md) > [MiddlewareMixin](./express.middlewaremixin.md)
## MiddlewareMixin() function
<b>Signature:</b>
```typescript
export declare function MiddlewareMixin<T extends MixinTarget<Context>>(superClass: T): {
new (...args: any[]): {
expressMiddleware(key: BindingAddress, middleware: ExpressRequestHandler | ExpressRequestHandler[], options?: MiddlewareBindingOptions | undefined): Binding<Middleware>;
expressMiddleware<CFG>(middlewareFactory: ExpressMiddlewareFactory<CFG>, middlewareConfig?: CFG | undefined, options?: MiddlewareBindingOptions | undefined): Binding<Middleware>;
expressMiddleware<CFG_1>(factoryOrKey: BindingAddress<Middleware> | ExpressMiddlewareFactory<CFG_1>, configOrHandler: ExpressRequestHandler | ExpressRequestHandler[] | CFG_1, options?: MiddlewareBindingOptions | undefined): Binding<Middleware>;
middleware(middleware: Middleware | Constructor<Provider<Middleware>>, options?: MiddlewareBindingOptions): Binding<Middleware>;
readonly name: string;
readonly subscriptionManager: loopbackContext.ContextSubscriptionManager;
scope: loopbackContext.BindingScope;
readonly parent: Context | undefined;
emitEvent: <T_1 extends loopbackContext.ContextEvent>(type: string, event: T_1) => void;
emitError: (err: unknown) => void;
bind: <ValueType = any>(key: BindingAddress<ValueType>) => Binding<ValueType>;
add: (binding: Binding<unknown>) => Context;
configure: <ConfigValueType = any>(key?: BindingAddress<unknown> | undefined) => Binding<ConfigValueType>;
getConfigAsValueOrPromise: <ConfigValueType_1>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ConfigValueType_1 | undefined>;
getConfig: <ConfigValueType_2>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
getConfigSync: <ConfigValueType_3>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
unbind: (key: BindingAddress<unknown>) => boolean;
subscribe: (observer: loopbackContext.ContextEventObserver) => loopbackContext.Subscription;
unsubscribe: (observer: loopbackContext.ContextEventObserver) => boolean;
close: () => void;
isSubscribed: (observer: loopbackContext.ContextObserver) => boolean;
createView: <T_2 = unknown>(filter: loopbackContext.BindingFilter, comparator?: loopbackContext.BindingComparator | undefined, options?: Omit<loopbackContext.ResolutionOptions, "session"> | undefined) => loopbackContext.ContextView<T_2>;
contains: (key: BindingAddress<unknown>) => boolean;
isBound: (key: BindingAddress<unknown>) => boolean;
getOwnerContext: (keyOrBinding: BindingAddress<unknown> | Readonly<Binding<unknown>>) => Context | undefined;
getScopedContext: (scope: loopbackContext.BindingScope.APPLICATION | loopbackContext.BindingScope.SERVER | loopbackContext.BindingScope.REQUEST) => Context | undefined;
getResolutionContext: (binding: Readonly<Binding<unknown>>) => Context | undefined;
isVisibleTo: (ctx: Context) => boolean;
find: <ValueType_1 = any>(pattern?: string | RegExp | loopbackContext.BindingFilter | undefined) => Readonly<Binding<ValueType_1>>[];
findByTag: <ValueType_2 = any>(tagFilter: RegExp | loopbackContext.BindingTag) => Readonly<Binding<ValueType_2>>[];
get: {
<ValueType_3>(keyWithPath: BindingAddress<ValueType_3>, session?: loopbackContext.ResolutionSession | undefined): Promise<ValueType_3>;
<ValueType_4>(keyWithPath: BindingAddress<ValueType_4>, options: loopbackContext.ResolutionOptions): Promise<ValueType_4 | undefined>;
};
getSync: {
<ValueType_5>(keyWithPath: BindingAddress<ValueType_5>, session?: loopbackContext.ResolutionSession | undefined): ValueType_5;
<ValueType_6>(keyWithPath: BindingAddress<ValueType_6>, options?: loopbackContext.ResolutionOptions | undefined): ValueType_6 | undefined;
};
getBinding: {
<ValueType_7 = any>(key: BindingAddress<ValueType_7>): Binding<ValueType_7>;
<ValueType_8>(key: BindingAddress<ValueType_8>, options?: {
optional?: boolean | undefined;
} | undefined): Binding<ValueType_8> | undefined;
};
findOrCreateBinding: <T_3>(key: BindingAddress<T_3>, policy?: loopbackContext.BindingCreationPolicy | undefined) => Binding<T_3>;
getValueOrPromise: <ValueType_9>(keyWithPath: BindingAddress<ValueType_9>, optionsOrSession?: loopbackContext.ResolutionOptionsOrSession | undefined) => loopbackContext.ValueOrPromise<ValueType_9 | undefined>;
toJSON: () => loopbackContext.JSONObject;
inspect: (options?: loopbackContext.ContextInspectOptions | undefined) => loopbackContext.JSONObject;
on: {
(eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Context;
(event: string | symbol, listener: (...args: any[]) => void): Context;
};
once: {
(eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Context;
(event: string | symbol, listener: (...args: any[]) => void): Context;
};
addListener: (event: string | symbol, listener: (...args: any[]) => void) => Context;
removeListener: (event: string | symbol, listener: (...args: any[]) => void) => Context;
off: (event: string | symbol, listener: (...args: any[]) => void) => Context;
removeAllListeners: (event?: string | symbol | undefined) => Context;
setMaxListeners: (n: number) => Context;
getMaxListeners: () => number;
listeners: (event: string | symbol) => Function[];
rawListeners: (event: string | symbol) => Function[];
emit: (event: string | symbol, ...args: any[]) => boolean;
listenerCount: (type: string | symbol) => number;
prependListener: (event: string | symbol, listener: (...args: any[]) => void) => Context;
prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => Context;
eventNames: () => (string | symbol)[];
};
} & T;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| superClass | T | |
<b>Returns:</b>
{ new (...args: any\[\]): { expressMiddleware(key: [BindingAddress](./context.bindingaddress.md)<!-- -->, middleware: [ExpressRequestHandler](./express.expressrequesthandler.md) \| [ExpressRequestHandler](./express.expressrequesthandler.md)<!-- -->\[\], options?: [MiddlewareBindingOptions](./express.middlewarebindingoptions.md) \| undefined): [Binding](./context.binding.md)<!-- --><[Middleware](./express.middleware.md)<!-- -->>; expressMiddleware<CFG>(middlewareFactory: [ExpressMiddlewareFactory](./express.expressmiddlewarefactory.md)<!-- --><CFG>, middlewareConfig?: CFG \| undefined, options?: [MiddlewareBindingOptions](./express.middlewarebindingoptions.md) \| undefined): [Binding](./context.binding.md)<!-- --><[Middleware](./express.middleware.md)<!-- -->>; expressMiddleware<CFG\_1>(factoryOrKey: [BindingAddress](./context.bindingaddress.md)<!-- --><[Middleware](./express.middleware.md)<!-- -->> \| [ExpressMiddlewareFactory](./express.expressmiddlewarefactory.md)<!-- --><CFG\_1>, configOrHandler: [ExpressRequestHandler](./express.expressrequesthandler.md) \| [ExpressRequestHandler](./express.expressrequesthandler.md)<!-- -->\[\] \| CFG\_1, options?: [MiddlewareBindingOptions](./express.middlewarebindingoptions.md) \| undefined): [Binding](./context.binding.md)<!-- --><[Middleware](./express.middleware.md)<!-- -->>; middleware(middleware: [Middleware](./express.middleware.md) \| [Constructor](./context.constructor.md)<!-- --><[Provider](./context.provider.md)<!-- --><[Middleware](./express.middleware.md)<!-- -->>>, options?: [MiddlewareBindingOptions](./express.middlewarebindingoptions.md)<!-- -->): [Binding](./context.binding.md)<!-- --><[Middleware](./express.middleware.md)<!-- -->>; readonly name: string; readonly subscriptionManager: loopbackContext.[ContextSubscriptionManager](./context.contextsubscriptionmanager.md)<!-- -->; scope: loopbackContext.[BindingScope](./context.bindingscope.md)<!-- -->; readonly parent: [Context](./context.context.md) \| undefined; emitEvent: <T\_1 extends loopbackContext.[ContextEvent](./context.contextevent.md)<!-- -->>(type: string, event: T\_1) => void; emitError: (err: unknown) => void; bind: <ValueType = any>(key: [BindingAddress](./context.bindingaddress.md)<!-- --><ValueType>) => [Binding](./context.binding.md)<!-- --><ValueType>; add: (binding: [Binding](./context.binding.md)<!-- --><unknown>) => [Context](./context.context.md)<!-- -->; configure: <ConfigValueType = any>(key?: [BindingAddress](./context.bindingaddress.md)<!-- --><unknown> \| undefined) => [Binding](./context.binding.md)<!-- --><ConfigValueType>; getConfigAsValueOrPromise: <ConfigValueType\_1>(key: [BindingAddress](./context.bindingaddress.md)<!-- --><unknown>, propertyPath?: string \| undefined, resolutionOptions?: loopbackContext.[ResolutionOptions](./context.resolutionoptions.md) \| undefined) => loopbackContext.[ValueOrPromise](./context.valueorpromise.md)<!-- --><ConfigValueType\_1 \| undefined>; getConfig: <ConfigValueType\_2>(key: [BindingAddress](./context.bindingaddress.md)<!-- --><unknown>, propertyPath?: string \| undefined, resolutionOptions?: loopbackContext.[ResolutionOptions](./context.resolutionoptions.md) \| undefined) => Promise<ConfigValueType\_2 \| undefined>; getConfigSync: <ConfigValueType\_3>(key: [BindingAddress](./context.bindingaddress.md)<!-- --><unknown>, propertyPath?: string \| undefined, resolutionOptions?: loopbackContext.[ResolutionOptions](./context.resolutionoptions.md) \| undefined) => ConfigValueType\_3 \| undefined; unbind: (key: [BindingAddress](./context.bindingaddress.md)<!-- --><unknown>) => boolean; subscribe: (observer: loopbackContext.[ContextEventObserver](./context.contexteventobserver.md)<!-- -->) => loopbackContext.[Subscription](./context.subscription.md)<!-- -->; unsubscribe: (observer: loopbackContext.[ContextEventObserver](./context.contexteventobserver.md)<!-- -->) => boolean; close: () => void; isSubscribed: (observer: loopbackContext.[ContextObserver](./context.contextobserver.md)<!-- -->) => boolean; createView: <T\_2 = unknown>(filter: loopbackContext.[BindingFilter](./context.bindingfilter.md)<!-- -->, comparator?: loopbackContext.[BindingComparator](./context.bindingcomparator.md) \| undefined, options?: Omit<loopbackContext.[ResolutionOptions](./context.resolutionoptions.md)<!-- -->, "session"> \| undefined) => loopbackContext.[ContextView](./context.contextview.md)<!-- --><T\_2>; contains: (key: [BindingAddress](./context.bindingaddress.md)<!-- --><unknown>) => boolean; isBound: (key: [BindingAddress](./context.bindingaddress.md)<!-- --><unknown>) => boolean; getOwnerContext: (keyOrBinding: [BindingAddress](./context.bindingaddress.md)<!-- --><unknown> \| Readonly<[Binding](./context.binding.md)<!-- --><unknown>>) => [Context](./context.context.md) \| undefined; getScopedContext: (scope: loopbackContext.[BindingScope.APPLICATION](./context.bindingscope.md) \| loopbackContext.[BindingScope.SERVER](./context.bindingscope.md) \| loopbackContext.[BindingScope.REQUEST](./context.bindingscope.md)<!-- -->) => [Context](./context.context.md) \| undefined; getResolutionContext: (binding: Readonly<[Binding](./context.binding.md)<!-- --><unknown>>) => [Context](./context.context.md) \| undefined; isVisibleTo: (ctx: [Context](./context.context.md)<!-- -->) => boolean; find: <ValueType\_1 = any>(pattern?: string \| RegExp \| loopbackContext.[BindingFilter](./context.bindingfilter.md) \| undefined) => Readonly<[Binding](./context.binding.md)<!-- --><ValueType\_1>>\[\]; findByTag: <ValueType\_2 = any>(tagFilter: RegExp \| loopbackContext.[BindingTag](./context.bindingtag.md)<!-- -->) => Readonly<[Binding](./context.binding.md)<!-- --><ValueType\_2>>\[\]; get: { <ValueType\_3>(keyWithPath: [BindingAddress](./context.bindingaddress.md)<!-- --><ValueType\_3>, session?: loopbackContext.[ResolutionSession](./context.resolutionsession.md) \| undefined): Promise<ValueType\_3>; <ValueType\_4>(keyWithPath: [BindingAddress](./context.bindingaddress.md)<!-- --><ValueType\_4>, options: loopbackContext.[ResolutionOptions](./context.resolutionoptions.md)<!-- -->): Promise<ValueType\_4 \| undefined>; }; getSync: { <ValueType\_5>(keyWithPath: [BindingAddress](./context.bindingaddress.md)<!-- --><ValueType\_5>, session?: loopbackContext.[ResolutionSession](./context.resolutionsession.md) \| undefined): ValueType\_5; <ValueType\_6>(keyWithPath: [BindingAddress](./context.bindingaddress.md)<!-- --><ValueType\_6>, options?: loopbackContext.[ResolutionOptions](./context.resolutionoptions.md) \| undefined): ValueType\_6 \| undefined; }; getBinding: { <ValueType\_7 = any>(key: [BindingAddress](./context.bindingaddress.md)<!-- --><ValueType\_7>): [Binding](./context.binding.md)<!-- --><ValueType\_7>; <ValueType\_8>(key: [BindingAddress](./context.bindingaddress.md)<!-- --><ValueType\_8>, options?: { optional?: boolean \| undefined; } \| undefined): [Binding](./context.binding.md)<!-- --><ValueType\_8> \| undefined; }; findOrCreateBinding: <T\_3>(key: [BindingAddress](./context.bindingaddress.md)<!-- --><T\_3>, policy?: loopbackContext.[BindingCreationPolicy](./context.bindingcreationpolicy.md) \| undefined) => [Binding](./context.binding.md)<!-- --><T\_3>; getValueOrPromise: <ValueType\_9>(keyWithPath: [BindingAddress](./context.bindingaddress.md)<!-- --><ValueType\_9>, optionsOrSession?: loopbackContext.[ResolutionOptionsOrSession](./context.resolutionoptionsorsession.md) \| undefined) => loopbackContext.[ValueOrPromise](./context.valueorpromise.md)<!-- --><ValueType\_9 \| undefined>; toJSON: () => loopbackContext.[JSONObject](./context.jsonobject.md)<!-- -->; inspect: (options?: loopbackContext.[ContextInspectOptions](./context.contextinspectoptions.md) \| undefined) => loopbackContext.[JSONObject](./context.jsonobject.md)<!-- -->; on: { (eventName: "bind" \| "unbind", listener: loopbackContext.[ContextEventListener](./context.contexteventlistener.md)<!-- -->): [Context](./context.context.md)<!-- -->; (event: string \| symbol, listener: (...args: any\[\]) => void): [Context](./context.context.md)<!-- -->; }; once: { (eventName: "bind" \| "unbind", listener: loopbackContext.[ContextEventListener](./context.contexteventlistener.md)<!-- -->): [Context](./context.context.md)<!-- -->; (event: string \| symbol, listener: (...args: any\[\]) => void): [Context](./context.context.md)<!-- -->; }; addListener: (event: string \| symbol, listener: (...args: any\[\]) => void) => [Context](./context.context.md)<!-- -->; removeListener: (event: string \| symbol, listener: (...args: any\[\]) => void) => [Context](./context.context.md)<!-- -->; off: (event: string \| symbol, listener: (...args: any\[\]) => void) => [Context](./context.context.md)<!-- -->; removeAllListeners: (event?: string \| symbol \| undefined) => [Context](./context.context.md)<!-- -->; setMaxListeners: (n: number) => [Context](./context.context.md)<!-- -->; getMaxListeners: () => number; listeners: (event: string \| symbol) => Function\[\]; rawListeners: (event: string \| symbol) => Function\[\]; emit: (event: string \| symbol, ...args: any\[\]) => boolean; listenerCount: (type: string \| symbol) => number; prependListener: (event: string \| symbol, listener: (...args: any\[\]) => void) => [Context](./context.context.md)<!-- -->; prependOnceListener: (event: string \| symbol, listener: (...args: any\[\]) => void) => [Context](./context.context.md)<!-- -->; eventNames: () => (string \| symbol)\[\]; }; } & T