MCPcopy
hub / github.com/nestjs/nest / applyCallbackToRouter

Method applyCallbackToRouter

packages/core/router/router-explorer.ts:155–273  ·  view source on GitHub ↗
(
    router: T,
    routeDefinition: RouteDefinition,
    instanceWrapper: InstanceWrapper,
    moduleKey: string,
    routePathMetadata: RoutePathMetadata,
    host: string | RegExp | Array<string | RegExp>,
  )

Source from the content-addressed store, hash-verified

153 }
154
155 private applyCallbackToRouter<T extends HttpServer>(
156 router: T,
157 routeDefinition: RouteDefinition,
158 instanceWrapper: InstanceWrapper,
159 moduleKey: string,
160 routePathMetadata: RoutePathMetadata,
161 host: string | RegExp | Array<string | RegExp>,
162 ) {
163 const {
164 path: paths,
165 requestMethod,
166 targetCallback,
167 methodName,
168 } = routeDefinition;
169
170 const { instance } = instanceWrapper;
171 const routerMethodRef = this.routerMethodFactory
172 .get(router, requestMethod)
173 .bind(router);
174
175 const isRequestScoped = !instanceWrapper.isDependencyTreeStatic();
176 const proxy = isRequestScoped
177 ? this.createRequestScopedHandler(
178 instanceWrapper,
179 requestMethod,
180 this.container.getModuleByKey(moduleKey)!,
181 moduleKey,
182 methodName,
183 )
184 : this.createCallbackProxy(
185 instance,
186 targetCallback,
187 methodName,
188 moduleKey,
189 requestMethod,
190 );
191
192 const isVersioned =
193 (routePathMetadata.methodVersion ||
194 routePathMetadata.controllerVersion) &&
195 routePathMetadata.versioningOptions;
196 let routeHandler = this.applyHostFilter(host, proxy);
197
198 paths.forEach(path => {
199 if (
200 isVersioned &&
201 routePathMetadata.versioningOptions!.type !== VersioningType.URI
202 ) {
203 // All versioning (except for URI Versioning) is done via the "Version Filter"
204 routeHandler = this.applyVersionFilter(
205 router,
206 routePathMetadata,
207 routeHandler,
208 );
209 }
210
211 routePathMetadata.methodPath = path;
212 const pathsToRegister = this.routePathFactory.create(

Callers 1

Calls 15

createCallbackProxyMethod · 0.95
applyHostFilterMethod · 0.95
applyVersionFilterMethod · 0.95
ROUTE_MAPPED_MESSAGEFunction · 0.90
getModuleByKeyMethod · 0.80
getHttpAdapterRefMethod · 0.80
getVersionMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected