-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
31 lines (25 loc) · 735 Bytes
/
Copy pathproxy.ts
File metadata and controls
31 lines (25 loc) · 735 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
27
28
29
30
31
import { NextRequest, NextResponse } from "next/server";
import crypto from "crypto";
const DEVICE_COOKIE = "hl_device_id";
const COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 2; // 2 years
export function proxy(request: NextRequest) {
const response = NextResponse.next();
const existing = request.cookies.get(DEVICE_COOKIE);
if (!existing) {
response.cookies.set({
name: DEVICE_COOKIE,
value: crypto.randomUUID(),
httpOnly: true,
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
path: "/",
maxAge: COOKIE_MAX_AGE,
});
}
return response;
}
export const config = {
matcher: [
"/((?!_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml).*)",
],
};