summaryrefslogtreecommitdiff
path: root/lib/server/hono
diff options
context:
space:
mode:
Diffstat (limited to 'lib/server/hono')
-rw-r--r--lib/server/hono/proxy.ts24
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();