From dd08023982e34cd66e1329beb65c55b8b1c7869a Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 17 Aug 2025 12:27:30 -0700 Subject: Bump pengueno and use common HonoProxy --- server/hono_proxy.ts | 71 ---------------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 server/hono_proxy.ts (limited to 'server/hono_proxy.ts') diff --git a/server/hono_proxy.ts b/server/hono_proxy.ts deleted file mode 100644 index f729819..0000000 --- a/server/hono_proxy.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { - BaseRequest, - Either, - IEither, - LogMetricTraceable, - Metric, - PenguenoRequest, - Server, - Signals, - TraceUtil, -} from '@emprespresso/pengueno'; - -import { serve, ServerType } from '@hono/node-server'; -import { 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)); - - constructor(private readonly server: Server) {} - - public async serve(port: number, hostname: string): Promise> { - return this.app - .map((tApp) => - Either.fromFailable(() => { - const app = tApp.get(); - app.all('*', async (c) => - tApp - .flatMap(TraceUtil.withMetricTrace(AppRequestMetric)) - .move(c.req) - .flatMap((tRequest) => PenguenoRequest.from(tRequest)) - .map((req) => this.server.serve(req)) - .map( - TraceUtil.promiseify((tResponse) => { - tResponse.trace.trace(AppRequestMetric.count.withValue(1.0)); - return new Response(tResponse.get().body(), tResponse.get()); - }), - ) - .get(), - ); - return serve({ - fetch: (_r) => app.fetch(_r), - port, - hostname, - }); - }), - ) - .peek(TraceUtil.traceResultingEither()) - .peek((tServe) => - tServe - .get() - .mapRight(() => - tServe.trace.trace( - `haii im still listening at http://${hostname}:${port} ~uwu dont think i forgot`, - ), - ), - ) - .map((tEitherServer) => - tEitherServer - .get() - .mapRight((server) => tEitherServer.move(server)) - .flatMapAsync((tServer) => Signals.awaitClose(tServer)), - ) - .peek(TraceUtil.promiseify(TraceUtil.traceResultingEither(AppLifetimeMetric))) - .get(); - } -} -- cgit v1.2.3-70-g09d2