Skip to content

Commit

Permalink
fix: config order
Browse files Browse the repository at this point in the history
  • Loading branch information
eddort committed Apr 20, 2023
1 parent c92f6d4 commit ac364d5
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/common/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,11 @@ dotenv.config({ path: resolve(appRoot.path, '.env') });

@Module({})
export class ConfigModule {
static async loadEnvOrFile(
static async readFile(
filePath: string,
envVarFile: string,
config: InMemoryConfiguration,
envName: string,
): Promise<string> {
// ENV should be non empty string
if (config[envName]) {
return config[envName];
}

const envVarFile = envName + '_FILE';
const filePath = config[envVarFile];

) {
try {
const fileContent = (await readFile(filePath, 'utf-8'))
.toString()
Expand All @@ -50,6 +43,19 @@ export class ConfigModule {
}
}
}
static async loadEnvOrFile(
config: InMemoryConfiguration,
envName: string,
): Promise<string> {
const envVarFile = envName + '_FILE';
const filePath = config[envVarFile];

if (filePath) {
return await this.readFile(filePath, envVarFile, config);
}

return config[envName];
}

static async loadSecrets(
config: InMemoryConfiguration,
Expand Down

0 comments on commit ac364d5

Please sign in to comment.