forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication-config.ts
More file actions
150 lines (119 loc) · 4.22 KB
/
Copy pathapplication-config.ts
File metadata and controls
150 lines (119 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import {
CanActivate,
ExceptionFilter,
NestInterceptor,
PipeTransform,
VersioningOptions,
WebSocketAdapter,
} from '@nestjs/common';
import { GlobalPrefixOptions } from '@nestjs/common/interfaces';
import { InstanceWrapper } from './injector/instance-wrapper';
import { ExcludeRouteMetadata } from './router/interfaces/exclude-route-metadata.interface';
export class ApplicationConfig {
private globalPrefix = '';
private globalPrefixOptions: GlobalPrefixOptions<ExcludeRouteMetadata> = {};
private globalPipes: Array<PipeTransform> = [];
private globalFilters: Array<ExceptionFilter> = [];
private globalInterceptors: Array<NestInterceptor> = [];
private globalGuards: Array<CanActivate> = [];
private versioningOptions: VersioningOptions;
private readonly globalRequestPipes: InstanceWrapper<PipeTransform>[] = [];
private readonly globalRequestFilters: InstanceWrapper<ExceptionFilter>[] =
[];
private readonly globalRequestInterceptors: InstanceWrapper<NestInterceptor>[] =
[];
private readonly globalRequestGuards: InstanceWrapper<CanActivate>[] = [];
constructor(private ioAdapter: WebSocketAdapter | null = null) {}
public setGlobalPrefix(prefix: string) {
this.globalPrefix = prefix;
}
public getGlobalPrefix() {
return this.globalPrefix;
}
public setGlobalPrefixOptions(
options: GlobalPrefixOptions<ExcludeRouteMetadata>,
) {
this.globalPrefixOptions = options;
}
public getGlobalPrefixOptions(): GlobalPrefixOptions<ExcludeRouteMetadata> {
return this.globalPrefixOptions;
}
public setIoAdapter(ioAdapter: WebSocketAdapter) {
this.ioAdapter = ioAdapter;
}
public getIoAdapter(): WebSocketAdapter {
return this.ioAdapter;
}
public addGlobalPipe(pipe: PipeTransform<any>) {
this.globalPipes.push(pipe);
}
public useGlobalPipes(...pipes: PipeTransform<any>[]) {
this.globalPipes = this.globalPipes.concat(pipes);
}
public getGlobalFilters(): ExceptionFilter[] {
return this.globalFilters;
}
public addGlobalFilter(filter: ExceptionFilter) {
this.globalFilters.push(filter);
}
public useGlobalFilters(...filters: ExceptionFilter[]) {
this.globalFilters = this.globalFilters.concat(filters);
}
public getGlobalPipes(): PipeTransform<any>[] {
return this.globalPipes;
}
public getGlobalInterceptors(): NestInterceptor[] {
return this.globalInterceptors;
}
public addGlobalInterceptor(interceptor: NestInterceptor) {
this.globalInterceptors.push(interceptor);
}
public useGlobalInterceptors(...interceptors: NestInterceptor[]) {
this.globalInterceptors = this.globalInterceptors.concat(interceptors);
}
public getGlobalGuards(): CanActivate[] {
return this.globalGuards;
}
public addGlobalGuard(guard: CanActivate) {
this.globalGuards.push(guard);
}
public useGlobalGuards(...guards: CanActivate[]) {
this.globalGuards = this.globalGuards.concat(guards);
}
public addGlobalRequestInterceptor(
wrapper: InstanceWrapper<NestInterceptor>,
) {
this.globalRequestInterceptors.push(wrapper);
}
public getGlobalRequestInterceptors(): InstanceWrapper<NestInterceptor>[] {
return this.globalRequestInterceptors;
}
public addGlobalRequestPipe(wrapper: InstanceWrapper<PipeTransform>) {
this.globalRequestPipes.push(wrapper);
}
public getGlobalRequestPipes(): InstanceWrapper<PipeTransform>[] {
return this.globalRequestPipes;
}
public addGlobalRequestFilter(wrapper: InstanceWrapper<ExceptionFilter>) {
this.globalRequestFilters.push(wrapper);
}
public getGlobalRequestFilters(): InstanceWrapper<ExceptionFilter>[] {
return this.globalRequestFilters;
}
public addGlobalRequestGuard(wrapper: InstanceWrapper<CanActivate>) {
this.globalRequestGuards.push(wrapper);
}
public getGlobalRequestGuards(): InstanceWrapper<CanActivate>[] {
return this.globalRequestGuards;
}
public enableVersioning(options: VersioningOptions): void {
if (Array.isArray(options.defaultVersion)) {
// Drop duplicated versions
options.defaultVersion = Array.from(new Set(options.defaultVersion));
}
this.versioningOptions = options;
}
public getVersioning(): VersioningOptions | undefined {
return this.versioningOptions;
}
}