From e719e5129f41e848a6d3d72d2951b4d9b5949d04 Mon Sep 17 00:00:00 2001 From: Djalim Simaila Date: Tue, 5 May 2026 14:50:17 +0200 Subject: [PATCH] feat: added logs --- routes/_middleware.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/routes/_middleware.ts b/routes/_middleware.ts index 2588e7b..2f0b173 100644 --- a/routes/_middleware.ts +++ b/routes/_middleware.ts @@ -43,6 +43,28 @@ export function getKey(user: string): string { } export const handler: MiddlewareHandler[] = [ + async function logRequest( + request: Request, + context: FreshContext, + ): Promise { + const url = new URL(request.url); + const start = performance.now(); + console.log(`--> ${request.method} ${url.pathname}${url.search}`); + + try { + const response = await context.next(); + + const duration = (performance.now() - start).toFixed(1); + console.log(`<-- ${request.method} ${url.pathname} ${response.status} (${duration}ms)`); + + return response; + } catch (error) { + const duration = (performance.now() - start).toFixed(1); + console.error(`<-- ${request.method} ${url.pathname} ERROR (${duration}ms)`); + console.error(error); + throw error; + } + }, /** * Check if user is authenticated and add session to context accordingly. * @param request The HTTP incomming request. -- 2.52.0