diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-07 15:15:35 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-07 15:15:35 -0800 |
| commit | eeca787c81ac92e46a9375a0b1ce8baa29852b1a (patch) | |
| tree | 0960a4a76b3f4c225a7e30c2c3e7981eb603b9e8 /lib/server/hono/proxy.ts | |
| parent | a8cc3f5312f6fa9a9675be4c68e209f45621c4a2 (diff) | |
| download | pengueno-eeca787c81ac92e46a9375a0b1ce8baa29852b1a.tar.gz pengueno-eeca787c81ac92e46a9375a0b1ce8baa29852b1a.zip | |
Lazily load hono
Diffstat (limited to 'lib/server/hono/proxy.ts')
| -rw-r--r-- | lib/server/hono/proxy.ts | 24 |
1 files changed, 18 insertions, 6 deletions
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<Hono>; 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<Hono>; + + return this.app; + } + public async serve(port: number, hostname: string): Promise<IEither<Error, void>> { - return this.app + const { serve } = await import('@hono/node-server'); + + const app = await this.initializeApp(); + return app .map((tApp) => Either.fromFailable<Error, ServerType>(() => { const app = tApp.get(); |
