UNPKG

@nestjs/core

Version:

The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.

141 lines (140 loc) • 4.2 kB
import { assertEnhancer, warnOnInvalidFilter, } from './helpers/assert-enhancer.js'; export class ApplicationConfig { ioAdapter; globalPrefix = ''; globalPrefixOptions = {}; globalPipes = []; globalFilters = []; globalInterceptors = []; globalGuards = []; globalPreRequestHooks = []; versioningOptions; routeConflictPolicy; routeResolutionStrategy; cookieSigner; globalRequestPipes = []; globalRequestFilters = []; globalRequestInterceptors = []; globalRequestGuards = []; constructor(ioAdapter = null) { this.ioAdapter = ioAdapter; } setGlobalPrefix(prefix) { this.globalPrefix = prefix; } getGlobalPrefix() { return this.globalPrefix; } setGlobalPrefixOptions(options) { this.globalPrefixOptions = options; } getGlobalPrefixOptions() { return this.globalPrefixOptions; } setIoAdapter(ioAdapter) { this.ioAdapter = ioAdapter; } getIoAdapter() { return this.ioAdapter; } addGlobalPipe(pipe) { this.globalPipes.push(pipe); } useGlobalPipes(...pipes) { pipes.forEach(item => item != null && assertEnhancer(item, 'pipe')); this.globalPipes = this.globalPipes.concat(pipes); } getGlobalFilters() { return this.globalFilters; } addGlobalFilter(filter) { this.globalFilters.push(filter); } useGlobalFilters(...filters) { filters.forEach(item => item != null && warnOnInvalidFilter(item)); this.globalFilters = this.globalFilters.concat(filters); } getGlobalPipes() { return this.globalPipes; } getGlobalInterceptors() { return this.globalInterceptors; } addGlobalInterceptor(interceptor) { this.globalInterceptors.push(interceptor); } useGlobalInterceptors(...interceptors) { interceptors.forEach(item => item != null && assertEnhancer(item, 'interceptor')); this.globalInterceptors = this.globalInterceptors.concat(interceptors); } getGlobalGuards() { return this.globalGuards; } addGlobalGuard(guard) { this.globalGuards.push(guard); } useGlobalGuards(...guards) { guards.forEach(item => item != null && assertEnhancer(item, 'guard')); this.globalGuards = this.globalGuards.concat(guards); } addGlobalRequestInterceptor(wrapper) { this.globalRequestInterceptors.push(wrapper); } getGlobalRequestInterceptors() { return this.globalRequestInterceptors; } addGlobalRequestPipe(wrapper) { this.globalRequestPipes.push(wrapper); } getGlobalRequestPipes() { return this.globalRequestPipes; } addGlobalRequestFilter(wrapper) { this.globalRequestFilters.push(wrapper); } getGlobalRequestFilters() { return this.globalRequestFilters; } addGlobalRequestGuard(wrapper) { this.globalRequestGuards.push(wrapper); } getGlobalRequestGuards() { return this.globalRequestGuards; } registerPreRequestHook(...hooks) { this.globalPreRequestHooks = this.globalPreRequestHooks.concat(hooks); } getGlobalPreRequestHooks() { return this.globalPreRequestHooks; } enableVersioning(options) { // Drop duplicated versions, on a copy: the options belong to the caller this.versioningOptions = Array.isArray(options.defaultVersion) ? { ...options, defaultVersion: Array.from(new Set(options.defaultVersion)), } : options; } getVersioning() { return this.versioningOptions; } setRouteConflictPolicy(policy) { this.routeConflictPolicy = policy; } getRouteConflictPolicy() { return this.routeConflictPolicy; } setRouteResolutionStrategy(strategy) { this.routeResolutionStrategy = strategy; } getRouteResolutionStrategy() { return this.routeResolutionStrategy; } setCookieSigner(signer) { this.cookieSigner = signer; } getCookieSigner() { return this.cookieSigner; } }