From 6f6616ce6cd53e4f31055de34d7bb98b1f228649 Mon Sep 17 00:00:00 2001 From: Wanjohi Date: Sun, 26 Oct 2025 00:45:15 +0300 Subject: [PATCH] feat: Add some more logging to hono --- packages/function/src/api/index.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/function/src/api/index.ts b/packages/function/src/api/index.ts index a6e4bb18..4eb6b289 100644 --- a/packages/function/src/api/index.ts +++ b/packages/function/src/api/index.ts @@ -1,22 +1,37 @@ +import z from "zod/v4"; import { Hono } from "hono"; +import { cors } from "hono/cors"; import { auth } from "./utils/auth"; -import { logger } from "hono/logger"; -import { openAPIRouteHandler } from "hono-openapi"; import { Log } from "@nestri/core/utils/log"; import { HTTPException } from "hono/http-exception"; import { VisibleError, ErrorCodes } from "@nestri/core/error"; +import { openAPIRouteHandler, validator } from "hono-openapi"; import packageJson from "../../package.json" assert { type: "json" }; const log = Log.create({ service: "api" }); export const app = new Hono(); app - .use(logger()) .use(async (c, next) => { c.header("Cache-Control", "no-store"); return next(); }) - .use(auth); + .use(async (c, next) => { + log.info("request", { + method: c.req.method, + path: c.req.path, + }); + const start = Date.now(); + await next(); + log.info("response", { + duration: Date.now() - start, + }); + }) + .use( + validator("header", z.object({ "x-nestri-member": z.string().optional() })), + ) + .use(auth) + .use(cors()); export const routes = app .get("/", async (c) => {