mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 00:18:19 +01:00
27 lines
873 B
TypeScript
27 lines
873 B
TypeScript
import { serverLogger } from "@versia-server/logging";
|
|
import { SHA256 } from "bun";
|
|
import chalk from "chalk";
|
|
import { createMiddleware } from "hono/factory";
|
|
|
|
export const logger = createMiddleware(async (context, next) => {
|
|
const body = await context.req.raw.clone().text();
|
|
|
|
const urlAndMethod = `${chalk.green(context.req.method)} ${chalk.blue(context.req.url)}`;
|
|
|
|
const hash = `${chalk.bold("Hash")}: ${chalk.yellow(
|
|
new SHA256().update(body).digest("hex"),
|
|
)}`;
|
|
|
|
const headers = `${chalk.bold("Headers")}:\n${Array.from(
|
|
context.req.raw.headers.entries(),
|
|
)
|
|
.map(([key, value]) => ` - ${chalk.cyan(key)}: ${chalk.white(value)}`)
|
|
.join("\n")}`;
|
|
|
|
const bodyLog = `${chalk.bold("Body")}: ${chalk.gray(body)}`;
|
|
|
|
serverLogger.debug`${urlAndMethod}\n${hash}\n${headers}\n${bodyLog}`;
|
|
|
|
await next();
|
|
});
|