-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
core.module.ts
44 lines (43 loc) · 1.36 KB
/
core.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { EmailModule } from '../email';
import { ConfigModule } from '../config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { LoggingInterceptor, TransformInterceptor } from './interceptors';
import { RequestContextMiddleware } from './context';
import { ConfigService } from '../config';
import { ConnectionOptions } from 'typeorm';
import { Notification } from '../notifications/notification.entity';
import { User } from '../auth/user.entity';
import { environment as env } from '@env-api/environment';
@Module({
imports: [
ConfigModule,
EmailModule.forRoot(env.email),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (config: ConfigService) => ({
...env.database,
entities: [Notification, User],
} as ConnectionOptions),
inject: [ConfigService],
}),
],
controllers: [],
providers: [
// Enable for debugging in Dev env.
// {
// provide: APP_INTERCEPTOR,
// useClass: LoggingInterceptor,
// },
{
provide: APP_INTERCEPTOR,
useClass: TransformInterceptor,
},
],
})
export class CoreModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(RequestContextMiddleware).forRoutes('*');
}
}