mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
14 lines
448 B
TypeScript
14 lines
448 B
TypeScript
import { MiddlewareHandler } from '@hono/hono';
|
|
|
|
import { httpRequestCounter, httpResponseCounter } from '@/metrics.ts';
|
|
|
|
export const metricsMiddleware: MiddlewareHandler = async (c, next) => {
|
|
const { method } = c.req;
|
|
httpRequestCounter.inc({ method });
|
|
|
|
await next();
|
|
|
|
const { status } = c.res;
|
|
const path = c.req.matchedRoutes.find((r) => r.method !== 'ALL')?.path ?? c.req.routePath;
|
|
httpResponseCounter.inc({ status, path });
|
|
};
|