mirror of
https://github.com/nestriness/nestri.git
synced 2026-08-01 17:34:15 +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 { 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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user