From 8d8ec4a1cdf6950b62bfa7b48675296657d08377 Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Tue, 27 Feb 2024 00:26:26 +0530 Subject: [PATCH] add uuid --- ui/middleware.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/middleware.ts b/ui/middleware.ts index 262b7eed79..2030488536 100644 --- a/ui/middleware.ts +++ b/ui/middleware.ts @@ -5,26 +5,27 @@ import { NextRequest, NextResponse, userAgent } from 'next/server'; const authMiddleware = withAuth({}); export default async function middleware(req: NextRequest, resp: NextResponse) { + const accessLogUUID = crypto.randomUUID(); const agent = userAgent(req); const xForwardedFor = req.headers.get('x-forwarded-for'); console.log( - `[${new Date().toISOString()}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)})` + `[${accessLogUUID}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)})` ); if (Configuration.authentication.PEERDB_PASSWORD) { const authRes = await (authMiddleware as any)(req); - const authResJson = NextResponse.next() + const authResJson = NextResponse.next(); console.log( - `[${new Date().toISOString()}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)}) ${authResJson.status}` + `[${accessLogUUID}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)}) ${authResJson.status}` ); return authRes; } - const res = NextResponse.next() + const res = NextResponse.next(); console.log( - `[${new Date().toISOString()}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)}) ${res.status}` + `[${accessLogUUID}] [${req.method} ${req.url}] [${req.ip} ${xForwardedFor}] (${JSON.stringify(agent.device)} ${JSON.stringify(agent.os)} ${JSON.stringify(agent.browser)}) ${res.status}` ); }