-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.service.ts
More file actions
43 lines (38 loc) · 1 KB
/
Copy pathconfig.service.ts
File metadata and controls
43 lines (38 loc) · 1 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
import { Injectable } from '@nestjs/common';
import { ApplicationConfig } from './config.interface';
import { loadConfig } from './config.helper';
/**
* Parses and interfaces with environment variable configs
*
* @export
* @class ConfigService
*/
@Injectable()
export class ConfigService {
private readonly applicationConfig: ApplicationConfig;
constructor() {
this.applicationConfig = loadConfig();
// We freeze the config to prevent modification
Object.freeze(this.applicationConfig);
}
/**
* Returns the value of a specified environment config
*
* @template T
* @param {T} configName
* @returns {ApplicationConfig[T]}
* @memberof ConfigService
*/
get<T extends keyof ApplicationConfig>(configName: T): ApplicationConfig[T] {
return this.applicationConfig[configName];
}
/**
* Returns entire environment config
*
* @returns {ApplicationConfig}
* @memberof ConfigService
*/
getConfigs(): ApplicationConfig {
return this.applicationConfig;
}
}