1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const response = NextResponse.next();
// Add custom header to all responses
response.headers.set("x-vinext-middleware", "active");
// Track visit count in cookie
const visits = Number.parseInt(
request.cookies.get("visit-count")?.value ?? "0",
10,
);
response.cookies.set("visit-count", String(visits + 1), { path: "/" });
return response;
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};