Skip to content

Commit

Permalink
* Fix config initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-kiriliuk committed Aug 27, 2024
1 parent 8c561d9 commit 2057c91
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 3 additions & 2 deletions lib/common/config/config.init-fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import { ConfigService } from "./config.service";
* This function used for initialize config store
*/
export const InitConfig = async () => {
const app = await NestFactory.createApplicationContext(ConfigModule);
const mod = ConfigModule.forInitializer();
const app = await NestFactory.createApplicationContext(mod);
await app.init();
const logger: Logger = app.select(LogModule).get(LOGGER);
EnvLoader.loadEnvironment(logger);
const configService = app.select(ConfigModule).get(ConfigService);
const configService = app.select(mod).get(ConfigService);
const genCnfDir = `${process.cwd()}/${process.env.CONFIG_SRC_DIR}`;
await configService.initWithPropertiesFiles(genCnfDir);
await app.close();
Expand Down
30 changes: 22 additions & 8 deletions lib/common/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Module } from "@nestjs/common";
import { DynamicModule, Module } from "@nestjs/common";
import { ConfigService } from "./config.service";
import { LogModule } from "../../shared/modules/log/log.module";
import { CacheModule } from "../../shared/modules/cache/cache.module";
Expand All @@ -24,10 +24,24 @@ import { ConfigController } from "./config.controller";
/**
* Module for work with system configuration.
*/
@Module({
imports: [LogModule, CacheModule, UserModule.forRoot()],
controllers: [ConfigController],
providers: [ConfigService],
exports: [ConfigService],
})
export class ConfigModule {}
@Module({})
export class ConfigModule {
static forRoot(): DynamicModule {
return {
module: ConfigModule,
imports: [LogModule, CacheModule, UserModule.forRoot()],
controllers: [ConfigController],
providers: [ConfigService],
exports: [ConfigService],
};
}

static forInitializer(): DynamicModule {
return {
module: ConfigModule,
imports: [LogModule, CacheModule],
providers: [ConfigService],
exports: [ConfigService],
};
}
}

0 comments on commit 2057c91

Please sign in to comment.