53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import * as configMaster from './config.json';
|
|
|
|
@Injectable()
|
|
export class AppConfigService {
|
|
defaultEnv = 'local';
|
|
constructor() {
|
|
}
|
|
|
|
private getValue(key: string, throwOnMissing = true): any {
|
|
const value = configMaster[this.defaultEnv].dbConfig[key];
|
|
if (!value && throwOnMissing) {
|
|
throw new Error(`config error - missing env.${key}`);
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
public ensureValues(keys: string[]) {
|
|
keys.forEach(k => this.getValue(k, true));
|
|
return this;
|
|
}
|
|
|
|
public getPort() {
|
|
return this.getValue('PORT', true);
|
|
}
|
|
|
|
public isProduction() {
|
|
const mode = this.getValue('MODE', false);
|
|
return mode != 'DEV';
|
|
}
|
|
|
|
getDbConfig() {
|
|
return configMaster[this.defaultEnv].dbConfig;
|
|
}
|
|
|
|
initializeFileSystem() {
|
|
return configMaster[this.defaultEnv].fileConfig;
|
|
}
|
|
|
|
getMailConfig() {
|
|
return configMaster[this.defaultEnv].mailConfig;
|
|
}
|
|
|
|
getJwtConfig(){
|
|
return configMaster[this.defaultEnv].jwtConfig;
|
|
}
|
|
|
|
getVapidConfig(){
|
|
return configMaster[this.defaultEnv].vapidConfig;
|
|
}
|
|
}
|