MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readBootstrap

Function readBootstrap

src/resolution/frameworks/nestjs.ts:363–399  ·  view source on GitHub ↗

`setGlobalPrefix` and `enableVersioning` from the file that calls `NestFactory.create`.

(safe: string)

Source from the content-addressed store, hash-verified

361
362/** `setGlobalPrefix` and `enableVersioning` from the file that calls `NestFactory.create`. */
363function 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/*`. */
402function isExcluded(path: string, excludes: readonly string[]): boolean {

Callers 1

postExtractFunction · 0.85

Calls 5

matchingCloseFunction · 0.85
versionValueFunction · 0.85
pushMethod · 0.80
splitTopLevelFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected