-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-config.service.ts
More file actions
35 lines (30 loc) · 1.04 KB
/
Copy pathapp-config.service.ts
File metadata and controls
35 lines (30 loc) · 1.04 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
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
/**
* Typed accessor over the raw {@link ConfigService}. Every consumer reads
* configuration through these getters instead of sprinkling string keys like
* `config.get('API_KEY')` around the codebase — one place to rename a key,
* change a default, or add parsing (e.g. CSV → string[]).
*/
@Injectable()
export class AppConfigService {
constructor(private readonly config: ConfigService) {}
get port(): number {
return this.config.get<number>('PORT', 4000);
}
get apiKey(): string {
return this.config.getOrThrow<string>('API_KEY');
}
get corsOrigins(): string[] {
return this.config
.getOrThrow<string>('CORS_ORIGIN')
.split(',')
.map((origin) => origin.trim())
.filter(Boolean);
}
/** Whether to seed demo tasks on first boot. Defaults to true; set
* `SEED_DATA=false` to start with an empty board. */
get seedEnabled(): boolean {
return this.config.get<string>('SEED_DATA') !== 'false';
}
}