From ee45e41d6de8a1542db9bf737baa99aca814bd0e Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 10 Oct 2024 00:39:58 +0100 Subject: [PATCH] update the logger --- projects/website/src/middleware.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/projects/website/src/middleware.ts b/projects/website/src/middleware.ts index cbd69c0..d11024b 100644 --- a/projects/website/src/middleware.ts +++ b/projects/website/src/middleware.ts @@ -1,9 +1,29 @@ -import type { NextRequest } from "next/server"; +import { NextResponse, type NextRequest } from "next/server"; import { isProduction } from "@ssr/common/utils/utils"; export function middleware(request: NextRequest) { + const before = performance.now(); + const response = NextResponse.next(); + // Log requests in production if (isProduction()) { - console.log(` ${request.method} ${request.url}`); + console.log( + ` ${request.method} ${request.nextUrl.pathname} ${response.status} in ${(performance.now() - before).toFixed(0)}ms` + ); } + + return response; } + +export const config = { + matcher: [ + /* + * Match all request paths except for the ones starting with: + * - api (API routes) + * - _next/static (static files) + * - _next/image (image optimization files) + * - favicon.ico (favicon file) + */ + "/((?!api|_next/static|_next/image|favicon.ico).*)", + ], +};