File tree Expand file tree Collapse file tree
notification/presentation/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626 "@nestjs/platform-express" : " ^11.0.1" ,
2727 "@nestjs/swagger" : " ^11.1.5" ,
2828 "@types/joi" : " ^17.2.2" ,
29- "dotenv" : " ^16.5.0" ,
3029 "joi" : " ^17.13.3" ,
3130 "mongoose" : " ^8.13.2" ,
3231 "reflect-metadata" : " ^0.2.2" ,
5150 "@typescript-eslint/eslint-plugin" : " ^8.30.1" ,
5251 "@typescript-eslint/parser" : " ^8.30.1" ,
5352 "concurrently" : " ^9.1.2" ,
53+ "dotenv" : " ^16.5.0" ,
5454 "eslint" : " ^9.18.0" ,
5555 "eslint-config-prettier" : " ^10.0.1" ,
5656 "eslint-plugin-prettier" : " ^5.2.2" ,
Original file line number Diff line number Diff line change 11import { Module } from '@nestjs/common' ;
22import { MongooseModule } from '@nestjs/mongoose' ;
3- import { ConfigModule } from '@nestjs/config' ;
3+ import { ConfigModule , ConfigService } from '@nestjs/config' ;
44import { NotificationModule } from './notification/notification.module' ;
55import { LoggerModule } from './logger/logger.module' ;
66
77@Module ( {
88 imports : [
9- ConfigModule . forRoot ( { isGlobal : true } ) ,
10- MongooseModule . forRoot (
11- process . env . MONGO_URI || 'mongodb://localhost:27017/smartedu' ,
12- ) ,
9+ ConfigModule . forRoot ( {
10+ isGlobal : true ,
11+ envFilePath : '.env' , // Explicit path to .env
12+ ignoreEnvFile : false , // Ensure it's not ignored
13+ } ) ,
14+ MongooseModule . forRootAsync ( {
15+ imports : [ ConfigModule ] ,
16+ useFactory : ( configService : ConfigService ) => {
17+ const uri = configService . get < string > ( 'MONGO_URL' ) ;
18+ if ( ! uri ) {
19+ throw new Error ( 'MONGO_URI not found in configuration' ) ;
20+ }
21+ return { uri } ;
22+ } ,
23+ inject : [ ConfigService ] ,
24+ } ) ,
1325 NotificationModule ,
1426 LoggerModule ,
1527 ] ,
Original file line number Diff line number Diff line change @@ -4,6 +4,14 @@ import { AllExceptionsFilter } from './filters/all-exceptions.filter';
44import { LoggerServiceFile } from './logger/services/logger.service.file' ;
55import { LoggerServiceDb } from './logger/services/logger.service.db' ;
66import { SwaggerModule , DocumentBuilder } from '@nestjs/swagger' ;
7+ import * as dotenv from 'dotenv' ;
8+ import * as path from 'path' ;
9+
10+ // 1. Load .env file manually first (as backup)
11+ const envPath = path . resolve ( __dirname , '../.env' ) ;
12+ dotenv . config ( { path : envPath } ) ;
13+
14+ console . log ( 'Environment variables loaded from:' , process . env . MONGO_URL ) ;
715
816async function bootstrap ( ) {
917 const app = await NestFactory . create ( AppModule ) ;
Original file line number Diff line number Diff line change @@ -162,10 +162,10 @@ export class LogController {
162162 async getLogStats (
163163 @Query ( 'level' ) level ?: string ,
164164 @Query ( 'context' ) context ?: string ,
165- ) : Promise < { data : Record < string , unknown > } > {
165+ ) : Promise < { data : Record < string , string > } > {
166166 const stats = ( await this . logService . getLogStats ( level , context ) ) as Record <
167167 string ,
168- unknown
168+ string
169169 > ;
170170 return { data : stats } ;
171171 }
You can’t perform that action at this time.
0 commit comments