Nestjs配置在引导级别访问配置
根据这一点,您可以在AppModule中导入配置。Nestjs配置在引导级别访问配置,nestjs,nestjs-swagger,nestjs-config,Nestjs,Nestjs Swagger,Nestjs Config,根据这一点,您可以在AppModule中导入配置。 我正在尝试访问main.ts文件中引导级别的配置。 大概是这样的: const app = await NestFactory.create(AppModule); if (config.get('swagger.enabled')) { initSwagger(app); } await app.listen(8080); @Injectable() export class SomeService { co
我正在尝试访问main.ts文件中引导级别的配置。 大概是这样的:
const app = await NestFactory.create(AppModule);
if (config.get('swagger.enabled'))
{
initSwagger(app);
}
await app.listen(8080);
@Injectable()
export class SomeService {
constructor(private readonly httpService: HttpService,
private readonly config: ConfigService) {}
}
问题是,在这一点上,我无法访问配置,只有其他moudle可以访问配置,如下所示:
const app = await NestFactory.create(AppModule);
if (config.get('swagger.enabled'))
{
initSwagger(app);
}
await app.listen(8080);
@Injectable()
export class SomeService {
constructor(private readonly httpService: HttpService,
private readonly config: ConfigService) {}
}
我的问题:如何在
main.ts
中的引导级别访问“nestjs config”,在创建服务器后,但在开始监听端口之前,您可以执行const config=app.get(ConfigService)
并访问ConfigService