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) => {