This repository has been archived by the owner on Nov 7, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
api.module.ts
73 lines (69 loc) 路 2.58 KB
/
api.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Module, NestModule } from '@nestjs/common';
import { SearchModule } from './search/search.module';
import { CharacterModule } from './character/character.module';
import { AuthenticationModule } from './authentication/authentication.module';
import { PostModule } from './post/post.module';
import { MiddlewaresConsumer } from '@nestjs/common/interfaces/middlewares';
import { RequestContextMiddleware } from './core/requestContext/requestContext.middleware';
import { AllianceModule } from './alliance/alliance.module';
import { CorporationModule } from './corporation/corporation.module';
import { LoggerModule } from './core/logger/logger.module';
import { UtilsModule } from './core/utils/utils.module';
import { CommentModule } from './comment/comment.module';
import { LoggerOptions } from 'typeorm/logger/LoggerOptions';
import { TypeOrmModule } from '@nestjs/typeorm';
import { NotificationModule } from './notification/notification.module';
import { AuthMiddleware } from './authentication/authentication.middleware';
import { WebsocketModule } from './websocket/websocket.module';
import { GooglePubSubModule } from './core/googlePubSub/googlePubSub.module';
import { MorganModule, MorganInterceptor } from 'nest-morgan';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { LOGGER_LEVEL } from './core/logger/logger.constants';
import { StatusModule } from './core/status/status.module';
import { FollowModule } from './follow/follow.module';
@Module({
imports: [
// Global
LoggerModule,
UtilsModule,
TypeOrmModule.forRoot({
type: 'postgres',
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT, 10),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
logging: <LoggerOptions>process.env.DB_LOG,
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
synchronize: process.env.DB_SYNC === 'true',
}),
GooglePubSubModule.forRoot(),
MorganModule.forRoot(),
StatusModule,
AuthenticationModule,
SearchModule,
AllianceModule,
CharacterModule,
CorporationModule,
PostModule,
CommentModule,
NotificationModule,
WebsocketModule,
FollowModule,
],
providers: [
{
provide: APP_INTERCEPTOR,
useClass: MorganInterceptor('combined', {
skip: (req, res) => process.env.LOG_LEVEL === LOGGER_LEVEL.INFO,
}),
},
],
})
export class ApiModule implements NestModule {
configure(consumer: MiddlewaresConsumer) {
consumer
.apply([RequestContextMiddleware, AuthMiddleware])
.forRoutes('*');
}
}