import type { INestApplication } from '@nestjs/common/interfaces'; import { NestFactory } from '@nestjs/core'; import { PlatformContext } from '../platform.context'; import type { PlatformAppMetadata, PlatformAppOptions } from '../types'; /** * Platform application itself. * * Just instantiate it, call run() method, and you are * ready to go! */ export class PlatformApp { readonly context: PlatformContext; constructor(readonly platformAppOptions: PlatformAppOptions) { this.context = new PlatformContext(platformAppOptions); } /** * Get all important information about PlatformApp instance * @returns Readonly metadata */ async getMetadata(): Promise> { return await this.context.getMetadata(); } /** * Runs application. * @returns Promise */ async run(): Promise { const context = this.context; const app = await this.createApplication(); await context.runConfiguredApplication(app); } /** * Создание и конфигурирование приложения по стандартному сценарию * Не путать с запуском * @private */ private async createApplication(): Promise { const context = this.context; const nestContext = await context.getNestFactoryCreateOptions(); const app = await NestFactory.create( await context.getRoot(), ...nestContext, ); await context.configureApp(app); return app; } }