mirror of
https://github.com/nestriness/nestri.git
synced 2026-08-02 01:35:18 +03:00
feat: Add some more logging to hono
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user