Nestjs Config 访问 bootstrap 级别的配置
Nestjs Config access to config in bootstrap level
根据这个 documentation 你在 AppModule 中导入你的配置。
我正在尝试访问 main.ts 文件中 bootstrap 级别的配置。
像这样:
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) {}
}
我的问题:如何在 bootstrap 级别
中访问 'nestjs-config'
在您的 main.ts
中,您可以执行 const config = app.get(ConfigService)
并在您创建服务器之后但在开始监听端口之前访问您的 ConfigService
。
根据这个 documentation 你在 AppModule 中导入你的配置。
我正在尝试访问 main.ts 文件中 bootstrap 级别的配置。
像这样:
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) {}
}
我的问题:如何在 bootstrap 级别
中访问 'nestjs-config'在您的 main.ts
中,您可以执行 const config = app.get(ConfigService)
并在您创建服务器之后但在开始监听端口之前访问您的 ConfigService
。