`setGlobalPrefix` and `enableVersioning` from the file that calls `NestFactory.create`.
(safe: string)
| 361 | |
| 362 | /** `setGlobalPrefix` and `enableVersioning` from the file that calls `NestFactory.create`. */ |
| 363 | function readBootstrap(safe: string): NestAppConfig { |
| 364 | const config: NestAppConfig = { prefix: '', excludes: [], uri: false, defaultVersion: null, versionPrefix: 'v' }; |
| 365 | const prefixCall = /\.setGlobalPrefix\s*\(/.exec(safe); |
| 366 | if (prefixCall) { |
| 367 | const open = prefixCall.index + prefixCall[0].length - 1; |
| 368 | const close = matchingClose(safe, open); |
| 369 | const args = close > open ? safe.slice(open + 1, close) : ''; |
| 370 | const lit = /^\s*(['"`])([^'"`$]*)\1/.exec(args); |
| 371 | if (lit) { |
| 372 | config.prefix = lit[2]!.replace(/^\/+|\/+$/g, ''); |
| 373 | const ex = /\bexclude\s*:\s*\[/.exec(args); |
| 374 | if (ex) { |
| 375 | const exOpen = ex.index + ex[0].length - 1; |
| 376 | const exClose = matchingClose(args, exOpen); |
| 377 | const list = exClose > exOpen ? args.slice(exOpen + 1, exClose) : ''; |
| 378 | for (const item of splitTopLevel(list)) { |
| 379 | const text = item.trim(); |
| 380 | const path = /^(['"])([^'"]*)\1$/.exec(text)?.[2] ?? /\bpath\s*:\s*(['"])([^'"]*)\1/.exec(text)?.[2]; |
| 381 | if (path !== undefined) config.excludes.push(path.replace(/^\/+/, '')); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | const versioning = /\.enableVersioning\s*\(/.exec(safe); |
| 387 | if (versioning) { |
| 388 | const open = versioning.index + versioning[0].length - 1; |
| 389 | const close = matchingClose(safe, open); |
| 390 | const args = close > open ? safe.slice(open + 1, close) : ''; |
| 391 | const type = /\btype\s*:\s*VersioningType\s*\.\s*(\w+)/.exec(args)?.[1]; |
| 392 | config.uri = type === undefined || type === 'URI'; |
| 393 | const def = /\bdefaultVersion\s*:\s*/.exec(args); |
| 394 | if (def) config.defaultVersion = versionValue(args.slice(def.index + def[0].length)); |
| 395 | const pre = /\bprefix\s*:\s*(false|(['"`])([^'"`]*)\2)/.exec(args); |
| 396 | if (pre) config.versionPrefix = pre[1] === 'false' ? '' : pre[3]!; |
| 397 | } |
| 398 | return config; |
| 399 | } |
| 400 | |
| 401 | /** A route excluded from the global prefix: `health`, `health/(.*)`, `health{/*wildcard}`, `health/*`. */ |
| 402 | function isExcluded(path: string, excludes: readonly string[]): boolean { |
no test coverage detected