deno.land / x / lume@v2.1.4 / middlewares / logger.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { brightGreen, gray, red } from "../deps/colors.ts";
import type { Middleware } from "../core/server.ts";
/** Log the request/responses */export default function log(): Middleware { return async (request, next) => { try { const response = await next(request); const url = new URL(request.url); const pathname = decodeURIComponent(url.pathname); const { status } = response;
if (status === 404 || status === 500) { console.log(`${red(status.toString())} ${pathname}`); } else if (status === 200) { console.log(`${brightGreen(status.toString())} ${pathname}`); } else if (status === 301 || status === 302) { console.log( `${gray(status.toString())} ${pathname} => ${ response.headers?.get( "location", ) }`, ); } else { console.log(`${gray(status.toString())} ${pathname}`); }
return response; } catch (cause) { return new Response( `Error: ${cause.toString()}`, { status: 500 }, ); } };}
lume

Version Info

Tagged at
a month ago