log connecting ip
All checks were successful
Deploy Website / deploy (push) Successful in 4m16s

This commit is contained in:
Lee 2024-10-10 02:25:54 +01:00
parent 526167d4f1
commit 19ab2a2e3d

@ -4,11 +4,12 @@ import { isProduction } from "@ssr/common/utils/utils";
export function middleware(request: NextRequest) {
const before = Date.now();
const response = NextResponse.next();
const connectingIp = request.headers.get("CF-Connecting-IP") || request.ip;
// Log requests in production
if (isProduction()) {
if (!isProduction()) {
console.log(
` ${request.method} ${request.nextUrl.pathname} ${response.status} in ${(Date.now() - before).toFixed(0)}ms`
` ${request.method} ${request.nextUrl.pathname}${connectingIp != undefined ? ` ${connectingIp}` : ""} ${response.status} in ${(Date.now() - before).toFixed(0)}ms`
);
}