import { DynamicModule , Module } from '@nestjs/common' ; import { ElasticsearchModule as EsModule } from '@nestjs/elasticsearch' ; import { ConfigModule , ConfigService } from '@fc/config' ; import { ElasticsearchConfig } from './dto' ; import { ClientOptions } from './interfaces' ; export { ElasticsearchService } from '@nestjs/elasticsearch' ; @ Module ( { } ) export class ElasticsearchModule { static register ( ) { return EsModule . registerAsync ( { imports : [ ConfigModule ] , inject : [ ConfigService ] , useFactory : ( config ) => useFactory ( config ) , } ) ; } } function useFactory ( config ) { const es = config . get < ElasticsearchConfig > ( 'Elasticsearch' ) ; const options = { node : `${ es . protocol }://${ es . host }:${ es . port }` , } ; return options ; }