-
Notifications
You must be signed in to change notification settings - Fork 228
/
app.module.ts
executable file
·80 lines (78 loc) · 2.44 KB
/
app.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
74
75
76
77
78
79
80
import { Module, ValidationPipe } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { APP_FILTER, APP_PIPE, RouterModule } from '@nestjs/core';
import { ServeStaticModule } from '@nestjs/serve-static';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { LoggerModule } from 'nestjs-pino';
import { AuthModule } from './auth';
import { BaseModule } from './base';
import { CommonModule, ExceptionsFilter } from './common';
import { configuration, loggerOptions } from './config';
import { SampleModule as DebugSampleModule } from './debug';
import { GqlModule } from './gql';
import { SampleModule } from './sample';
@Module({
imports: [
// https://getpino.io
// https://github.com/iamolegga/nestjs-pino
LoggerModule.forRoot(loggerOptions),
// Configuration
// https://docs.nestjs.com/techniques/configuration
ConfigModule.forRoot({
isGlobal: true,
load: [configuration],
}),
// Database
// https://docs.nestjs.com/techniques/database
TypeOrmModule.forRootAsync({
useFactory: (config: ConfigService) => ({
...config.get<TypeOrmModuleOptions>('db'),
}),
inject: [ConfigService],
}),
// Static Folder
// https://docs.nestjs.com/recipes/serve-static
// https://docs.nestjs.com/techniques/mvc
ServeStaticModule.forRoot({
rootPath: `${__dirname}/../public`,
renderPath: '/',
}),
// Service Modules
AuthModule, // Global for Middleware
CommonModule, // Global
BaseModule,
SampleModule,
GqlModule,
DebugSampleModule,
// Module Router
// https://docs.nestjs.com/recipes/router-module
RouterModule.register([
{
path: 'test',
module: SampleModule,
},
{
path: 'test',
module: DebugSampleModule,
},
]),
],
providers: [
// Global Guard, Authentication check on all routers
// { provide: APP_GUARD, useClass: AuthenticatedGuard },
// Global Filter, Exception check
{ provide: APP_FILTER, useClass: ExceptionsFilter },
// Global Pipe, Validation check
// https://docs.nestjs.com/pipes#global-scoped-pipes
// https://docs.nestjs.com/techniques/validation
{
provide: APP_PIPE,
useValue: new ValidationPipe({
// disableErrorMessages: true,
transform: true, // transform object to DTO class
whitelist: true,
}),
},
],
})
export class AppModule {}