MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / RestComponent

Class RestComponent

packages/rest/src/rest.component.ts:50–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48import {AjvFactoryProvider} from './validation/ajv-factory.provider';
49
50export class RestComponent implements Component {
51 providers: ProviderMap = {
52 [RestBindings.AJV_FACTORY.key]: AjvFactoryProvider,
53 };
54 /**
55 * Add built-in body parsers
56 */
57 bindings: Binding[] = [
58 ...createActionBindings(),
59 // FIXME(rfeng): We now register request body parsers in TRANSIENT scope
60 // so that they can be bound at application or server level
61 Binding.bind(RestBindings.REQUEST_BODY_PARSER).toClass(RequestBodyParser),
62 createBodyParserBinding(
63 JsonBodyParser,
64 RestBindings.REQUEST_BODY_PARSER_JSON,
65 ),
66 createBodyParserBinding(
67 TextBodyParser,
68 RestBindings.REQUEST_BODY_PARSER_TEXT,
69 ),
70 createBodyParserBinding(
71 UrlEncodedBodyParser,
72 RestBindings.REQUEST_BODY_PARSER_URLENCODED,
73 ),
74 createBodyParserBinding(
75 RawBodyParser,
76 RestBindings.REQUEST_BODY_PARSER_RAW,
77 ),
78 createBodyParserBinding(
79 StreamBodyParser,
80 RestBindings.REQUEST_BODY_PARSER_STREAM,
81 ),
82 createBindingFromClass(InfoSpecEnhancer),
83 createBindingFromClass(ConsolidationEnhancer),
84
85 ...getRestMiddlewareBindings(),
86 ];
87 servers: {
88 [name: string]: Constructor<Server>;
89 } = {
90 RestServer,
91 };
92
93 constructor(
94 @inject(CoreBindings.APPLICATION_INSTANCE) app: Application,
95 @inject(RestBindings.CONFIG) config?: RestComponentConfig,
96 ) {
97 // Register the `InvokeMiddleware` with default to `ACTION_MIDDLEWARE_CHAIN`
98 // to keep backward compatibility with action based sequence
99 const invokeMiddlewareActionBinding = createBindingFromClass(
100 InvokeMiddlewareProvider,
101 {
102 key: RestBindings.SequenceActions.INVOKE_MIDDLEWARE,
103 },
104 ).tag({[CoreTags.EXTENSION_POINT]: RestTags.ACTION_MIDDLEWARE_CHAIN});
105 app.add(invokeMiddlewareActionBinding);
106
107 // Register the `InvokeMiddleware` with default to `DEFAULT_MIDDLEWARE_CHAIN`

Callers

nothing calls this directly

Calls 6

createBodyParserBindingFunction · 0.90
createActionBindingsFunction · 0.85
createBindingFromClassFunction · 0.85
toClassMethod · 0.80
bindMethod · 0.45

Tested by

no test coverage detected