configuration/src/app.module.ts

76 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-10-25 07:09:45 +00:00
import { HealthModule, HealthModuleOptions } from '@mobicoop/health-module';
import { MessagerModule } from '@modules/messager/messager.module';
2023-01-25 09:50:05 +00:00
import { Module } from '@nestjs/common';
2023-10-24 13:47:11 +00:00
import { ConfigModule, ConfigService } from '@nestjs/config';
2023-10-25 07:09:45 +00:00
import { HEALTH_CRITICAL_LOGGING_KEY, SERVICE_NAME } from './app.constants';
import { MessagePublisherPort } from '@mobicoop/ddd-library';
import {
ConfigurationModuleOptions,
ConfigurationModule as ConfigurationModulePackage,
} from '@mobicoop/configuration-module';
import { MESSAGE_PUBLISHER } from '@modules/messager/messager.di-tokens';
import { ConfigurationModule } from '@modules/configuration/configuration.module';
import { EventEmitterModule } from '@nestjs/event-emitter';
2023-10-24 09:21:45 +00:00
import brokerConfig from './config/broker.config';
import carpoolConfig from './config/carpool.config';
import paginationConfig from './config/pagination.config';
import serviceConfig from './config/service.config';
2023-10-24 13:47:11 +00:00
import redisConfig from './config/redis.config';
2023-10-25 07:09:45 +00:00
import { Transport } from '@nestjs/microservices';
2023-10-31 08:14:07 +00:00
import matchConfig from './config/match.config';
2023-01-25 09:50:05 +00:00
@Module({
2023-01-25 14:16:13 +00:00
imports: [
2023-10-24 09:21:45 +00:00
ConfigModule.forRoot({
isGlobal: true,
load: [
brokerConfig,
carpoolConfig,
2023-10-31 08:14:07 +00:00
matchConfig,
2023-10-24 09:21:45 +00:00
paginationConfig,
2023-10-24 13:47:11 +00:00
redisConfig,
2023-10-24 09:21:45 +00:00
serviceConfig,
],
}),
EventEmitterModule.forRoot(),
HealthModule.forRootAsync({
2023-10-25 07:09:45 +00:00
imports: [MessagerModule, ConfigModule],
inject: [MESSAGE_PUBLISHER, ConfigService],
useFactory: async (
messagePublisher: MessagePublisherPort,
2023-10-25 07:09:45 +00:00
configService: ConfigService,
): Promise<HealthModuleOptions> => ({
serviceName: SERVICE_NAME,
criticalLoggingKey: HEALTH_CRITICAL_LOGGING_KEY,
2023-10-25 07:09:45 +00:00
messagePublisher,
checkMicroservices: [
{
2023-10-25 07:09:45 +00:00
host: configService.get<string>('redis.host') as string,
port: configService.get<string>('redis.port') as string,
password: configService.get<string>('redis.password'),
name: 'Redis',
transport: Transport.REDIS,
},
],
}),
}),
ConfigurationModulePackage.forRootAsync({
2023-10-24 13:47:11 +00:00
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (
configService: ConfigService,
): Promise<ConfigurationModuleOptions> => {
2023-10-24 13:47:11 +00:00
return {
host: configService.get<string>('redis.host') as string,
port: configService.get<number>('redis.port') as number,
password: configService.get<string>('redis.password'),
2023-10-24 13:47:11 +00:00
};
},
}),
2023-01-25 14:16:13 +00:00
ConfigurationModule,
MessagerModule,
2023-01-25 14:16:13 +00:00
],
exports: [ConfigurationModule, MessagerModule],
2023-01-25 09:50:05 +00:00
})
export class AppModule {}