generated from bastian/boilerplate
113 lines
3.0 KiB
TypeScript
113 lines
3.0 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService as NestConfigService } from '@nestjs/config';
|
|
import type { AppConfig, NodeEnv } from './config.types';
|
|
|
|
@Injectable()
|
|
export class AppConfigService {
|
|
private readonly config: AppConfig;
|
|
|
|
constructor(private readonly nestConfig: NestConfigService<AppConfig, true>) {
|
|
this.config = {
|
|
nodeEnv: this.nestConfig.getOrThrow('nodeEnv', { infer: true }),
|
|
port: this.nestConfig.getOrThrow('port', { infer: true }),
|
|
appBaseUrl: this.nestConfig.getOrThrow('appBaseUrl', { infer: true }),
|
|
frontendBaseUrl: this.nestConfig.getOrThrow('frontendBaseUrl', {
|
|
infer: true,
|
|
}),
|
|
trustProxy: this.nestConfig.getOrThrow('trustProxy', { infer: true }),
|
|
database: this.nestConfig.getOrThrow('database', { infer: true }),
|
|
oidc: this.nestConfig.getOrThrow('oidc', { infer: true }),
|
|
session: this.nestConfig.getOrThrow('session', { infer: true }),
|
|
corsOrigins: this.nestConfig.getOrThrow('corsOrigins', { infer: true }),
|
|
csrfHeaderName: this.nestConfig.getOrThrow('csrfHeaderName', {
|
|
infer: true,
|
|
}),
|
|
logLevel: this.nestConfig.getOrThrow('logLevel', { infer: true }),
|
|
swaggerEnabled: this.nestConfig.getOrThrow('swaggerEnabled', {
|
|
infer: true,
|
|
}),
|
|
documents: this.nestConfig.getOrThrow('documents', { infer: true }),
|
|
reminders: this.nestConfig.getOrThrow('reminders', { infer: true }),
|
|
rateLimit: this.nestConfig.getOrThrow('rateLimit', { infer: true }),
|
|
};
|
|
}
|
|
|
|
get nodeEnv(): NodeEnv {
|
|
return this.config.nodeEnv;
|
|
}
|
|
|
|
get isProduction(): boolean {
|
|
return this.config.nodeEnv === 'production';
|
|
}
|
|
|
|
get port(): number {
|
|
return this.config.port;
|
|
}
|
|
|
|
get appBaseUrl(): string {
|
|
return this.config.appBaseUrl;
|
|
}
|
|
|
|
get frontendBaseUrl(): string {
|
|
return this.config.frontendBaseUrl;
|
|
}
|
|
|
|
get trustProxy(): boolean {
|
|
return this.config.trustProxy;
|
|
}
|
|
|
|
get database(): AppConfig['database'] {
|
|
return this.config.database;
|
|
}
|
|
|
|
get oidc(): AppConfig['oidc'] {
|
|
return this.config.oidc;
|
|
}
|
|
|
|
get session(): AppConfig['session'] {
|
|
return this.config.session;
|
|
}
|
|
|
|
get corsOrigins(): string[] {
|
|
return this.config.corsOrigins;
|
|
}
|
|
|
|
get csrfHeaderName(): string {
|
|
return this.config.csrfHeaderName;
|
|
}
|
|
|
|
get logLevel(): string {
|
|
return this.config.logLevel;
|
|
}
|
|
|
|
get swaggerEnabled(): boolean {
|
|
return this.config.swaggerEnabled;
|
|
}
|
|
|
|
get documents(): AppConfig['documents'] {
|
|
return this.config.documents;
|
|
}
|
|
|
|
get reminders(): AppConfig['reminders'] {
|
|
return this.config.reminders;
|
|
}
|
|
|
|
get rateLimit(): AppConfig['rateLimit'] {
|
|
return this.config.rateLimit;
|
|
}
|
|
|
|
/**
|
|
* @deprecated Use rateLimit.global.windowSeconds.
|
|
*/
|
|
get rateLimitWindowSeconds(): number {
|
|
return this.config.rateLimit.global.windowSeconds;
|
|
}
|
|
|
|
/**
|
|
* @deprecated Use rateLimit.global.maxRequests.
|
|
*/
|
|
get rateLimitMaxRequests(): number {
|
|
return this.config.rateLimit.global.maxRequests;
|
|
}
|
|
}
|