feat: added logs
Build and push image / Check Deno code (push) Has been cancelled
Build and push image / Build Docker image (push) Has been cancelled

This commit was merged in pull request #156.
This commit is contained in:
2026-05-05 14:50:17 +02:00
committed by djalim
parent a6042087dc
commit e64c3881fe
+22
View File
@@ -43,6 +43,28 @@ export function getKey(user: string): string {
}
export const handler: MiddlewareHandler<State>[] = [
async function logRequest(
request: Request,
context: FreshContext<State>,
): Promise<Response> {
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.