fennec-be/src/app.module.ts
2021-01-31 19:42:17 +08:00

45 lines
1.5 KiB
TypeScript

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { GraphQLModule } from '@nestjs/graphql';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppResolver } from './app.resolver';
import { AppService } from './app.service';
import { ProjectsModule } from './projects/projects.module';
import configuration from './commons/config/configuration';
@Module({
imports: [
ConfigModule.forRoot({
load: [configuration],
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (cnfigService: ConfigService) => ({
type: 'postgres',
host: cnfigService.get<string>('db.postgres.host'),
port: cnfigService.get<number>('db.postgres.port'),
username: cnfigService.get<string>('db.postgres.username'),
password: cnfigService.get<string>('db.postgres.password'),
database: cnfigService.get<string>('db.postgres.database'),
synchronize: true,
autoLoadEntities: true,
}),
inject: [ConfigService],
}),
GraphQLModule.forRootAsync({
imports: [ConfigModule],
useFactory: (cnfigService: ConfigService) => ({
debug: cnfigService.get<string>('env') !== 'prod',
playground: true,
autoSchemaFile: true,
}),
inject: [ConfigService],
}),
ProjectsModule,
],
controllers: [AppController],
providers: [AppService, AppResolver],
})
export class AppModule {}