Hi,
We run our nest server in multiple environments and would like the ability to optionally import modules based on certain configuration parameters. For example, we would like certain modules to only be imported and enabled in dev until they are mature enough to push to prod.
I have seen this issue: https://github.com/nestjs/nest/issues/9868. But this suggestion requires us to use process.env directly which we would like to avoid given the way we have our env and configuration set up.
It seems a little weird that if our configuration or feature flags were hosted in an external service we could do this easily, but cannot if our configuration is managed by a nest dependency.
If this works:
static async registerAsync(): DynamicModule {
const enabled = await loadExternalFlag();
if (enabled) {
return { /* the full module */ };
}
return { /* an empty module */ };
}
It seems strange that we are handicapped by the fact that our config is managed by a nest module and cannot do something like:
static async registerAsync(@Inject() config: ConfigService): DynamicModule {
const enabled = await config.get('flag');
if (enabled) {
return { /* the full module */ };
}
return { /* an empty module */ };
}
Is there a way around this that allows us to import and use an imported provider?