mirror of
https://github.com/versia-pub/server.git
synced 2026-03-12 21:39:15 +01:00
refactor(api): 🔊 Move HTTP logs to logtape/hono
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 1s
Build Docker Images / lint (push) Failing after 7s
Build Docker Images / check (push) Failing after 6s
Build Docker Images / tests (push) Failing after 6s
Build Docker Images / detect-circular (push) Failing after 6s
Deploy Docs to GitHub Pages / build (push) Failing after 0s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 0s
Nix Build / check (push) Failing after 1s
Test Publish / build (client) (push) Failing after 0s
Test Publish / build (sdk) (push) Failing after 0s
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 1s
Build Docker Images / lint (push) Failing after 7s
Build Docker Images / check (push) Failing after 6s
Build Docker Images / tests (push) Failing after 6s
Build Docker Images / detect-circular (push) Failing after 6s
Deploy Docs to GitHub Pages / build (push) Failing after 0s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 0s
Nix Build / check (push) Failing after 1s
Test Publish / build (client) (push) Failing after 0s
Test Publish / build (sdk) (push) Failing after 0s
This commit is contained in:
parent
a2d7c323f6
commit
de69f27877
9 changed files with 15 additions and 50 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { Scalar } from "@scalar/hono-api-reference";
|
||||
import { config } from "@versia-server/config";
|
||||
import { ApiError } from "@versia-server/kit";
|
||||
import { honoLogger } from "@versia-server/logging";
|
||||
import { Hono } from "hono";
|
||||
import { serveStatic } from "hono/bun";
|
||||
import { cors } from "hono/cors";
|
||||
|
|
@ -15,7 +16,6 @@ import type { ApiRouteExports, HonoEnv } from "../../types/api.ts";
|
|||
import { agentBans } from "./middlewares/agent-bans.ts";
|
||||
import { boundaryCheck } from "./middlewares/boundary-check.ts";
|
||||
import { ipBans } from "./middlewares/ip-bans.ts";
|
||||
import { logger } from "./middlewares/logger.ts";
|
||||
import { rateLimit } from "./middlewares/rate-limit.ts";
|
||||
import { routes } from "./routes.ts";
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ export const appFactory = async (): Promise<Hono<HonoEnv>> => {
|
|||
|
||||
app.use(ipBans);
|
||||
app.use(agentBans);
|
||||
app.use(logger);
|
||||
app.use(honoLogger);
|
||||
app.use(boundaryCheck);
|
||||
app.use(
|
||||
"/api/*",
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
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();
|
||||
});
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
import type { Hook } from "@hono/standard-validator";
|
||||
import type { RolePermission } from "@versia/client/schemas";
|
||||
import { config } from "@versia-server/config";
|
||||
import { serverLogger } from "@versia-server/logging";
|
||||
import { extractParams, verifySolution } from "altcha-lib";
|
||||
import chalk from "chalk";
|
||||
import { eq, type SQL } from "drizzle-orm";
|
||||
import type { Context, Hono, MiddlewareHandler, ValidationTargets } from "hono";
|
||||
import { every } from "hono/combine";
|
||||
|
|
@ -417,19 +415,3 @@ export const jsonOrForm = (): MiddlewareHandler<HonoEnv> => {
|
|||
await next();
|
||||
});
|
||||
};
|
||||
|
||||
export const debugResponse = async (res: Response): Promise<void> => {
|
||||
const body = await res.clone().text();
|
||||
|
||||
const status = `${chalk.bold("Status")}: ${chalk.green(res.status)}`;
|
||||
|
||||
const headers = `${chalk.bold("Headers")}:\n${Array.from(
|
||||
res.headers.entries(),
|
||||
)
|
||||
.map(([key, value]) => ` - ${chalk.cyan(key)}: ${chalk.white(value)}`)
|
||||
.join("\n")}`;
|
||||
|
||||
const bodyLog = `${chalk.bold("Body")}: ${chalk.gray(body)}`;
|
||||
|
||||
serverLogger.debug`${status}\n${headers}\n${bodyLog}`;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { mkdir } from "node:fs/promises";
|
||||
import { dirname } from "node:path";
|
||||
import { getFileSink, getRotatingFileSink } from "@logtape/file";
|
||||
import { honoLogger as logtapeHonoLogger } from "@logtape/hono";
|
||||
import {
|
||||
configure,
|
||||
getConsoleSink,
|
||||
|
|
@ -100,6 +101,7 @@ await configure({
|
|||
category: "server",
|
||||
sinks: getSinkNames(),
|
||||
},
|
||||
{ category: ["http"], sinks: getSinkNames() },
|
||||
{
|
||||
category: ["federation", "inbox"],
|
||||
sinks: getSinkNames(),
|
||||
|
|
@ -148,3 +150,7 @@ export const federationMessagingLogger = getLogger(["federation", "messaging"]);
|
|||
export const databaseLogger = getLogger("database");
|
||||
export const webfingerLogger = getLogger("webfinger");
|
||||
export const sonicLogger = getLogger("sonic");
|
||||
export const honoLogger = logtapeHonoLogger({
|
||||
category: "http",
|
||||
level: "debug",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
"@logtape/file": "catalog:",
|
||||
"@logtape/sentry": "catalog:",
|
||||
"@logtape/otel": "catalog:",
|
||||
"@logtape/hono": "catalog:",
|
||||
"@sentry/bun": "catalog:",
|
||||
"chalk": "catalog:"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue