From f1d7ffb9dd6e540568ef0f7d2d342bc689851bc9 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Sat, 23 Mar 2024 00:08:44 +0000 Subject: [PATCH] Fix env path for Nestjs --- apps/server/src/database/typeorm.config.ts | 3 +-- apps/server/src/helpers/utils.ts | 4 ++++ .../server/src/integrations/environment/environment.module.ts | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/server/src/database/typeorm.config.ts b/apps/server/src/database/typeorm.config.ts index 544dfcdd..4cf36053 100644 --- a/apps/server/src/database/typeorm.config.ts +++ b/apps/server/src/database/typeorm.config.ts @@ -1,8 +1,7 @@ import { DataSource } from 'typeorm'; import * as dotenv from 'dotenv'; import { NamingStrategy } from './naming-strategy'; -import * as path from 'path'; -const envPath = path.resolve(process.cwd(), '..', '..', '.env'); +import { envPath } from '../helpers/utils'; dotenv.config({ path: envPath }); diff --git a/apps/server/src/helpers/utils.ts b/apps/server/src/helpers/utils.ts index e1d7a234..42168594 100644 --- a/apps/server/src/helpers/utils.ts +++ b/apps/server/src/helpers/utils.ts @@ -1,5 +1,9 @@ +import * as path from 'path'; + export function generateHostname(name: string): string { let hostname = name.replace(/[^a-z0-9]/gi, '').toLowerCase(); hostname = hostname.substring(0, 30); return hostname; } + +export const envPath = path.resolve(process.cwd(), '..', '..', '.env'); diff --git a/apps/server/src/integrations/environment/environment.module.ts b/apps/server/src/integrations/environment/environment.module.ts index 8c4bd454..7c6acfa2 100644 --- a/apps/server/src/integrations/environment/environment.module.ts +++ b/apps/server/src/integrations/environment/environment.module.ts @@ -2,6 +2,7 @@ import { Global, Module } from '@nestjs/common'; import { EnvironmentService } from './environment.service'; import { ConfigModule } from '@nestjs/config'; import { validate } from './environment.validation'; +import { envPath } from '../../helpers/utils'; @Global() @Module({ @@ -9,6 +10,7 @@ import { validate } from './environment.validation'; ConfigModule.forRoot({ isGlobal: true, expandVariables: true, + envFilePath: envPath, validate, }), ],