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

Method create

packages/core/router/route-path-factory.ts:21–78  ·  view source on GitHub ↗
(
    metadata: RoutePathMetadata,
    requestMethod?: RequestMethod,
  )

Source from the content-addressed store, hash-verified

19 constructor(private readonly applicationConfig: ApplicationConfig) {}
20
21 public create(
22 metadata: RoutePathMetadata,
23 requestMethod?: RequestMethod,
24 ): string[] {
25 let paths = [''];
26
27 const versionOrVersions = this.getVersion(metadata);
28 if (
29 versionOrVersions &&
30 metadata.versioningOptions?.type === VersioningType.URI
31 ) {
32 const versionPrefix = this.getVersionPrefix(metadata.versioningOptions);
33
34 if (Array.isArray(versionOrVersions)) {
35 paths = flatten(
36 paths.map(path =>
37 versionOrVersions.map(version =>
38 // Version Neutral - Do not include version in URL
39 version === VERSION_NEUTRAL
40 ? path
41 : `${path}/${versionPrefix}${version}`,
42 ),
43 ),
44 );
45 } else {
46 // Version Neutral - Do not include version in URL
47 if (versionOrVersions !== VERSION_NEUTRAL) {
48 paths = paths.map(
49 path => `${path}/${versionPrefix}${versionOrVersions}`,
50 );
51 }
52 }
53 }
54
55 paths = this.appendToAllIfDefined(paths, metadata.modulePath);
56 paths = this.appendToAllIfDefined(paths, metadata.ctrlPath);
57 paths = this.appendToAllIfDefined(paths, metadata.methodPath);
58
59 if (metadata.globalPrefix) {
60 paths = paths.map(path => {
61 if (
62 this.isExcludedFromGlobalPrefix(
63 path,
64 requestMethod,
65 versionOrVersions,
66 metadata.versioningOptions,
67 )
68 ) {
69 return path;
70 }
71 return stripEndSlash(metadata.globalPrefix || '') + path;
72 });
73 }
74
75 return paths
76 .map(path => addLeadingSlash(path || '/'))
77 .map(path => (path !== '/' ? stripEndSlash(path) : path));
78 }

Callers

nothing calls this directly

Calls 7

getVersionMethod · 0.95
getVersionPrefixMethod · 0.95
appendToAllIfDefinedMethod · 0.95
flattenFunction · 0.90
stripEndSlashFunction · 0.90
addLeadingSlashFunction · 0.90

Tested by

no test coverage detected