feat: Add some more logging to hono

This commit is contained in:
Wanjohi
2025-10-26 00:45:15 +03:00
parent a3ad061c25
commit 6f6616ce6c

View File

@@ -1,22 +1,37 @@
import z from "zod/v4";
import { Hono } from "hono"; import { Hono } from "hono";
import { cors } from "hono/cors";
import { auth } from "./utils/auth"; import { auth } from "./utils/auth";
import { logger } from "hono/logger";
import { openAPIRouteHandler } from "hono-openapi";
import { Log } from "@nestri/core/utils/log"; import { Log } from "@nestri/core/utils/log";
import { HTTPException } from "hono/http-exception"; import { HTTPException } from "hono/http-exception";
import { VisibleError, ErrorCodes } from "@nestri/core/error"; import { VisibleError, ErrorCodes } from "@nestri/core/error";
import { openAPIRouteHandler, validator } from "hono-openapi";
import packageJson from "../../package.json" assert { type: "json" }; import packageJson from "../../package.json" assert { type: "json" };
const log = Log.create({ service: "api" }); const log = Log.create({ service: "api" });
export const app = new Hono(); export const app = new Hono();
app app
.use(logger())
.use(async (c, next) => { .use(async (c, next) => {
c.header("Cache-Control", "no-store"); c.header("Cache-Control", "no-store");
return next(); 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 export const routes = app
.get("/", async (c) => { .get("/", async (c) => {