import type { AppConfig } from "../../presentation/config/AppConfig"; import type { AppContainerFactory } from "../AppContainerFactory"; import { FrontendRuntime } from "./FrontendRuntime"; import { CodemationHonoApiApp } from "../../presentation/http/hono/CodemationHonoApiAppFactory"; import type { HeadlessHttpServerFactory } from "../../presentation/http/HeadlessHttpServerFactory"; import type { Logger } from "../../application/logging/Logger"; export class HeadlessApiRuntime { constructor( private readonly appContainerFactory: AppContainerFactory, private readonly httpServerFactory: HeadlessHttpServerFactory, private readonly logger: Logger, ) {} async start(appConfig: AppConfig): Promise { const port = Number(appConfig.env.PORT ?? 4001); this.logger.info(`Starting codemation headless API runtime`); this.logger.info(`HTTP port: ${port}`); const container = await this.appContainerFactory.create({ appConfig, }); await container.resolve(FrontendRuntime).start(); const honoApp = container.resolve(CodemationHonoApiApp); const httpServer = this.httpServerFactory.create(honoApp, port, this.logger); await new Promise((resolve) => { httpServer.listen(port, () => { this.logger.info(`codemation headless API listening on port ${port}`); resolve(); }); }); } }