-
Notifications
You must be signed in to change notification settings - Fork 158
/
app.module.ts
60 lines (58 loc) · 1.98 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
import { APP_INTERCEPTOR, APP_GUARD } from '@nestjs/core';
import { Module, Logger } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from 'nestjs-config';
import { UserModule } from './core/user/user.module';
import { LoggingInterceptor } from './shared/interceptor/logging.interceptor';
import { AuthGuard } from './shared/guard/auth.guard';
import { CurlModule } from './core/curl/curl.module';
import { UploadFileModule } from './core/upload-file/upload-file.module';
import { FileModule } from './file/file.module';
import { RoleModule } from './core/role/role.module';
import { ResourceModule } from './core/resource/resource.module';
import * as path from 'path';
const entitiesPath =
process.env.NODE_ENV === 'production'
? path.resolve('./**/*.entity.js')
: path.resolve('./**/*.entity.ts');
Logger.log(process.env.NODE_ENV, '当前环境');
@Module({
imports: [
ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}'), {
modifyConfigName: name => name.replace('.config', ''),
}), // 配置加载配置文件
TypeOrmModule.forRootAsync({
useFactory: async (config: ConfigService) => ({
type: config.get('database.type'),
host: config.get('database.host'),
port: config.get('database.port'),
username: config.get('database.username'),
password: config.get('database.password'),
database: config.get('database.database'),
entities: [entitiesPath],
synchronize: config.get('database.synchronize'),
logging: config.get('database.logging'),
}),
inject: [ConfigService],
}),
UserModule,
ConfigModule,
CurlModule,
UploadFileModule,
FileModule,
RoleModule,
ResourceModule,
],
controllers: [],
providers: [
{
provide: APP_INTERCEPTOR,
useClass: LoggingInterceptor,
},
{
provide: APP_GUARD,
useClass: AuthGuard,
},
],
})
export class AppModule {}