Skip to content

Commit

Permalink
Merge pull request #471 from lsst-epo/462-add-middleware-to-log
Browse files Browse the repository at this point in the history
Omitting localhost from middleware logging
  • Loading branch information
ericdrosas87 authored Jun 11, 2024
2 parents c7581a1 + e43df4e commit 6cc7b20
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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"],
},
};

Expand Down Expand Up @@ -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: "/((?!_________).*)",
};

0 comments on commit 6cc7b20

Please sign in to comment.