Skip to content

Commit

Permalink
Refactor: Set ignoreEnvFile
Browse files Browse the repository at this point in the history
환경에 따라 서버에서 실행되는 경우 ignoreEnvFile==true 가 되도록 설정
  • Loading branch information
sally0226 committed Jun 27, 2024
1 parent c4eb0b7 commit 77df854
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MikroOrmModule } from '@mikro-orm/nestjs';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { getEnvPath } from './common/helper/env.helper';
import { getEnvPath, ignoreEnvFile } from './common/helper/env.helper';
import { envValidation } from './common/helper/env.validation';
import { MapModule } from './map/map.module';
import { UserMapModule } from './user-map/user-map.module';
Expand All @@ -19,6 +19,7 @@ import { UserModule } from './user/user.module';
envFilePath: getEnvPath(`${__dirname}/..`),
cache: true,
validate: envValidation,
ignoreEnvFile: ignoreEnvFile,
}),
MikroOrmModule.forRoot(),
AuthModule,
Expand Down
7 changes: 7 additions & 0 deletions src/common/helper/env.helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { resolve } from 'path';

import { NODE_ENVIRONMENT } from './env.validation';

export const getEnvPath = (dest: string): string => {
const env: string = process.env.NODE_ENV;
const filename: string = env ? `.${env}.env` : '.development.env';
return resolve(`${dest}/${filename}`);
};

export const ignoreEnvFile = ((): boolean => {
const env = process.env.NODE_ENV;
return env === NODE_ENVIRONMENT.stage || env === NODE_ENVIRONMENT.production;
})();
6 changes: 3 additions & 3 deletions src/common/helper/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ const stage = 'stage';
const production = 'production';
const test = 'test';

const nodeEnvironment = {
export const NODE_ENVIRONMENT = {
[development]: development,
[stage]: stage,
[production]: production,
[test]: test,
};

export class EnvironmentVariables {
@IsEnum(nodeEnvironment)
NODE_ENV: keyof typeof nodeEnvironment;
@IsEnum(NODE_ENVIRONMENT)
NODE_ENV: keyof typeof NODE_ENVIRONMENT;

@IsString()
DB_HOST: string;
Expand Down

0 comments on commit 77df854

Please sign in to comment.