From eeca787c81ac92e46a9375a0b1ce8baa29852b1a Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 7 Dec 2025 15:15:35 -0800 Subject: Lazily load hono --- lib/server/hono/proxy.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'lib/server/hono/proxy.ts') diff --git a/lib/server/hono/proxy.ts b/lib/server/hono/proxy.ts index f729819..7f93804 100644 --- a/lib/server/hono/proxy.ts +++ b/lib/server/hono/proxy.ts @@ -10,21 +10,33 @@ import { TraceUtil, } from '@emprespresso/pengueno'; -import { serve, ServerType } from '@hono/node-server'; -import { Hono } from 'hono'; +import type { ServerType } from '@hono/node-server'; +import type { Hono } from 'hono'; const AppLifetimeMetric = Metric.fromName('HonoAppLifetime').asResult(); const AppRequestMetric = Metric.fromName('HonoAppRequest'); export class HonoProxy { - private readonly app = LogMetricTraceable.of(new Hono()) - .flatMap(TraceUtil.withTrace(`AppId = ${crypto.randomUUID()}`)) - .flatMap(TraceUtil.withMetricTrace(AppLifetimeMetric)); + private app?: LogMetricTraceable; constructor(private readonly server: Server) {} + private async initializeApp() { + if (this.app) return this.app; + + const { Hono } = await import('hono'); + this.app = LogMetricTraceable.of(new Hono()) + .flatMap(TraceUtil.withTrace(`AppId = ${crypto.randomUUID()}`)) + .flatMap(TraceUtil.withMetricTrace(AppLifetimeMetric)) as LogMetricTraceable; + + return this.app; + } + public async serve(port: number, hostname: string): Promise> { - return this.app + const { serve } = await import('@hono/node-server'); + + const app = await this.initializeApp(); + return app .map((tApp) => Either.fromFailable(() => { const app = tApp.get(); -- cgit v1.2.3-70-g09d2