2

根据此文档 ,您将配置导入 AppModule。
我正在尝试在我的 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) {}
}

我的问题:如何在引导级别访问“nestjs-config”

4

1 回答 1

12

在您创建服务器之后,但在开始侦听端口之前,main.ts您可以执行const config = app.get(ConfigService)并访问您的。ConfigService

于 2019-12-23T19:38:27.727 回答