From e43df4e23cc8e9b91ee8c71372762ac917190ec9 Mon Sep 17 00:00:00 2001 From: Eric Rosas Date: Tue, 11 Jun 2024 14:08:19 -0700 Subject: [PATCH] Omitting localhost from middleware logging Omitting localhost from middleware logging --- middleware.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/middleware.js b/middleware.js index 6b2015ea..d16091f8 100644 --- a/middleware.js +++ b/middleware.js @@ -6,7 +6,10 @@ const ignorableFileExtensions = ["woff", "ico", "png", "jpeg", "jpg"]; export function middleware(request) { // Filter out file extensions we don't care about if ( - !ignorableFileExtensions.some((e) => request.nextUrl.pathname.includes(e)) + !ignorableFileExtensions.some((e) => + request.nextUrl.pathname.includes(e) + ) && + !request.nextUrl.href.includes("localhost") ) { // Insight into API server: const logEntry = { @@ -16,6 +19,8 @@ export function middleware(request) { href: request.nextUrl.href, method: request.method, client_ip: request.ip, + userAgent: request?.headers?.["user-agent"], + xForwardedFor: request?.headers?.["x-forwarded-for"], }, }; @@ -48,5 +53,5 @@ export function middleware(request) { // Match anything and let the middleware decide to redirect or log export const config = { - matcher: "/((?!localhost).*)", + matcher: "/((?!_________).*)", };