-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
26 lines (21 loc) · 772 Bytes
/
proxy.ts
File metadata and controls
26 lines (21 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
import { ipAddress } from "@vercel/functions";
import { incrViews } from "./actions/middleware/views";
import { processIp } from "./lib/utils";
export const config = {
matcher: ["/", "/notes", "/about", "/photography", "/posts/:path*"],
};
export default async function proxy(
request: NextRequest,
context: NextFetchEvent
) {
const response = NextResponse.next();
const forwardedIp = request.headers.get("x-forwarded-for");
const rawIp = forwardedIp
? forwardedIp.split(/, /)[0]
: ipAddress(request) ?? "unknown";
const ip = processIp(rawIp);
// TODO: Add categories for each individual blog post.
await incrViews(ip, context, ["global_views"]);
return response;
}