feat: performance tracker
This commit is contained in:
@@ -2,17 +2,17 @@
|
||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
||||
import { DomainError } from "@lib/errors.ts";
|
||||
import { getCookies } from "https://deno.land/std@0.197.0/http/cookie.ts";
|
||||
import { decode, verify } from "https://deno.land/x/djwt@v2.2/mod.ts";
|
||||
import { sessionDB, userDB } from "@lib/db.ts";
|
||||
import { verify } from "https://deno.land/x/djwt@v2.2/mod.ts";
|
||||
import * as cache from "@lib/cache/performance.ts";
|
||||
import { JWT_SECRET } from "@lib/env.ts";
|
||||
|
||||
export async function handler(
|
||||
_req: Request,
|
||||
req: Request,
|
||||
ctx: MiddlewareHandlerContext,
|
||||
) {
|
||||
try {
|
||||
ctx.state.flag = true;
|
||||
const allCookies = getCookies(_req.headers);
|
||||
performance.mark("a");
|
||||
const allCookies = getCookies(req.headers);
|
||||
const sessionCookie = allCookies["session_cookie"];
|
||||
if (!ctx.state.session && sessionCookie && JWT_SECRET) {
|
||||
try {
|
||||
@@ -22,9 +22,15 @@ export async function handler(
|
||||
}
|
||||
} catch (_err) {
|
||||
//
|
||||
console.log({ _err });
|
||||
}
|
||||
}
|
||||
return await ctx.next();
|
||||
|
||||
const resp = await ctx.next();
|
||||
performance.mark("b");
|
||||
const b = performance.measure("a->b", "a", "b");
|
||||
cache.savePerformance(req.url, b.duration);
|
||||
return resp;
|
||||
} catch (error) {
|
||||
console.error("Error", error);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user