Nestjs 使用Nest.js从DI获取应用程序url

Nestjs 使用Nest.js从DI获取应用程序url,nestjs,Nestjs,在main.ts中,我们可以使用app.getUrl()获取应用程序url 是否可以通过DI从服务中获取 async function bootstrap() { const app = await NestFactory.create(AppModule); await app.listen(3000); console.log(`Application is running on: ${await app.getUrl()}`); } bootstrap(); 您可

在main.ts中,我们可以使用app.getUrl()获取应用程序url

是否可以通过DI从服务中获取

async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    await app.listen(3000);
    console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();

您可以在引导方法之外定义
app
变量并将其导出:

export let app: INestApplication;

async function bootstrap() {
    app = await NestFactory.create(AppModule);
    await app.listen(3000);
    console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();