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

Method constructor

packages/rest/src/rest.server.ts:209–245  ·  view source on GitHub ↗

* * Creates an instance of RestServer. * * @param app - The application instance (injected via * CoreBindings.APPLICATION_INSTANCE). * @param config - The configuration options (injected via * RestBindings.CONFIG). *

(
    @inject(CoreBindings.APPLICATION_INSTANCE) app: Application,
    @inject(RestBindings.CONFIG, {optional: true})
    config: RestServerConfig = {},
  )

Source from the content-addressed store, hash-verified

207 *
208 */
209 constructor(
210 @inject(CoreBindings.APPLICATION_INSTANCE) app: Application,
211 @inject(RestBindings.CONFIG, {optional: true})
212 config: RestServerConfig = {},
213 ) {
214 super(app);
215 this.scope = BindingScope.SERVER;
216
217 this.config = resolveRestServerConfig(config);
218
219 this.bind(RestBindings.PORT).to(this.config.port);
220 this.bind(RestBindings.HOST).to(config.host);
221 this.bind(RestBindings.PATH).to(config.path);
222 this.bind(RestBindings.PROTOCOL).to(config.protocol ?? 'http');
223 this.bind(RestBindings.HTTPS_OPTIONS).to(config as ServerOptions);
224
225 if (config.requestBodyParser) {
226 this.bind(RestBindings.REQUEST_BODY_PARSER_OPTIONS).to(
227 config.requestBodyParser,
228 );
229 }
230
231 if (config.sequence) {
232 this.sequence(config.sequence);
233 } else {
234 this.sequence(MiddlewareSequence);
235 }
236
237 if (config.router) {
238 this.bind(RestBindings.ROUTER_OPTIONS).to(config.router);
239 }
240
241 this.basePath(config.basePath);
242
243 this.bind(RestBindings.BASE_PATH).toDynamicValue(() => this._basePath);
244 this.bind(RestBindings.HANDLER).toDynamicValue(() => this.httpHandler);
245 }
246
247 protected _setupOASEnhancerIfNeeded() {
248 if (this.oasEnhancerService != null) return;

Callers

nothing calls this directly

Calls 7

sequenceMethod · 0.95
basePathMethod · 0.95
injectFunction · 0.85
resolveRestServerConfigFunction · 0.85
toMethod · 0.80
toDynamicValueMethod · 0.80
bindMethod · 0.45

Tested by

no test coverage detected