@@ -4,6 +4,8 @@ import { AppController } from './app.controller';
44import { AppService } from './app.service' ;
55import { TypeOrmModule } from '@nestjs/typeorm' ;
66import { SchedulerModule } from './scheduler/scheduler.module' ;
7+ import { APP_GUARD } from '@nestjs/core' ;
8+ import { ApiKeyGuard } from './guards/api-key.guard' ;
79
810@Module ( {
911 imports : [
@@ -12,35 +14,35 @@ import { SchedulerModule } from './scheduler/scheduler.module';
1214 imports : [ ConfigModule ] ,
1315 inject : [ ConfigService ] ,
1416 useFactory : ( config : ConfigService ) => {
15- const dbType = config . get < string > ( 'DB_TYPE' , 'sqlite' ) ;
17+ const dbType = config . get < string > ( 'DB_TYPE' ) ;
1618 const entities = [ __dirname + '/**/*.entity{.ts,.js}' ] ;
1719
18- if ( dbType === 'mysql' ) {
19- return {
20- type : 'mysql' as const ,
21- host : config . get < string > ( 'DATABASE_HOST' , 'localhost' ) ,
22- port : parseInt ( config . get < string > ( 'DATABASE_PORT' , '3306' ) , 10 ) ,
23- username : config . get < string > ( 'DATABASE_USER' , 'root' ) ,
24- password : config . get < string > ( 'DATABASE_PASSWORD' , '' ) ,
25- database : config . get < string > ( 'DATABASE_NAME' , 'scheduler' ) ,
26- entities,
27- synchronize : config . get < string > ( 'DB_SYNC' , 'false' ) === 'true' ,
28- logging : config . get < string > ( 'DB_LOGGING' , 'false' ) === 'true' ,
29- } ;
20+ if ( dbType !== 'mysql' ) {
21+ throw new Error ( 'Only MySQL database is supported. Please check DB_TYPE in .env' ) ;
3022 }
3123
3224 return {
33- type : 'sqlite' as const ,
34- database : config . get < string > ( 'DB_FILE' , 'database.sqlite' ) ,
25+ type : 'mysql' as const ,
26+ host : config . get < string > ( 'DATABASE_HOST' , 'localhost' ) ,
27+ port : parseInt ( config . get < string > ( 'DATABASE_PORT' , '3306' ) , 10 ) ,
28+ username : config . get < string > ( 'DATABASE_USER' , 'root' ) ,
29+ password : config . get < string > ( 'DATABASE_PASSWORD' , '' ) ,
30+ database : config . get < string > ( 'DATABASE_NAME' , 'scheduler' ) ,
3531 entities,
36- synchronize : true ,
37- logging : false ,
32+ synchronize : config . get < string > ( 'DB_SYNC' , 'false' ) === ' true' ,
33+ logging : config . get < string > ( 'DB_LOGGING' , ' false' ) === 'true' ,
3834 } ;
3935 } ,
4036 } ) ,
4137 SchedulerModule ,
4238 ] ,
4339 controllers : [ AppController ] ,
44- providers : [ AppService ] ,
40+ providers : [
41+ AppService ,
42+ {
43+ provide : APP_GUARD ,
44+ useClass : ApiKeyGuard ,
45+ } ,
46+ ] ,
4547} )
46- export class AppModule { }
48+ export class AppModule { }
0 commit comments