在 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();