-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.module.ts
More file actions
83 lines (81 loc) · 2.63 KB
/
app.module.ts
File metadata and controls
83 lines (81 loc) · 2.63 KB
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
81
82
83
/* eslint-disable @typescript-eslint/require-await */
import { Logger, Module } from '@nestjs/common';
import { CallModule } from './modules/call/call.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import configuration from './config/configuration';
import { SequelizeModule, SequelizeModuleOptions } from '@nestjs/sequelize';
import { format } from 'sql-formatter';
import { UserModule } from './modules/user/user.module';
import { WebhookModule } from './modules/webhook/webhook.module';
const defaultDbConfig = (
configService: ConfigService,
): SequelizeModuleOptions => ({
dialect: 'postgres' as const,
autoLoadModels: true,
synchronize: false,
pool: {
max: 20,
min: 0,
idle: 20000,
acquire: 20000,
},
dialectOptions: configService.get<boolean>('isProduction')
? {
ssl: {
require: true,
rejectUnauthorized: false,
},
application_name: 'meet-server',
}
: {},
logging: !configService.get<boolean>('database.debug')
? false
: (content: string) => {
const parse = content.match(/^(Executing \(.*\):) (.*)$/);
if (parse) {
const prettySql = format(parse[2], { language: 'postgresql' });
Logger.debug(`${parse[1]}\n${prettySql}`);
} else {
Logger.debug(`Could not parse sql content: ${content}`);
}
},
});
@Module({
imports: [
ConfigModule.forRoot({
envFilePath: [`.env.${process.env.NODE_ENV}`],
load: [configuration],
isGlobal: true,
}),
SequelizeModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
host: configService.get('database.host'),
port: configService.get('database.port'),
username: configService.get('database.username'),
password: configService.get('database.password'),
database: configService.get('database.database'),
...defaultDbConfig(configService),
}),
}),
SequelizeModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
name: 'drive',
useFactory: async (configService: ConfigService) => ({
host: configService.get('driveDatabase.host'),
port: configService.get('driveDatabase.port'),
username: configService.get('driveDatabase.username'),
password: configService.get('driveDatabase.password'),
database: configService.get('driveDatabase.database'),
...defaultDbConfig(configService),
}),
}),
CallModule,
UserModule,
WebhookModule,
],
controllers: [],
})
export class AppModule {}