-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathproxy.ts
More file actions
59 lines (47 loc) · 1.42 KB
/
proxy.ts
File metadata and controls
59 lines (47 loc) · 1.42 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { createMiddleware, defaults, withVercelToolbar } from "@nosecone/next";
import type { NoseconeOptions } from "@nosecone/next";
import { getSessionCookie } from "better-auth/cookies";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export const noseconeOptions: NoseconeOptions = {
...defaults,
contentSecurityPolicy: false,
};
export const noseconeOptionsWithToolbar: NoseconeOptions =
withVercelToolbar(noseconeOptions);
const securityHeaders = createMiddleware(noseconeOptions);
const PUBLIC_PATHS = [
"/",
"/how-it-works",
"/sign-in",
"/sign-up",
"/robots.txt",
"/sitemap.xml",
"/api/auth",
"/api/agent",
"/api/snapshot",
"/monitoring",
"/.well-known/workflow",
];
const isPublic = (pathname: string) =>
PUBLIC_PATHS.some((p) => pathname === p || pathname.startsWith(`${p}/`));
const proxy = (request: NextRequest) => {
const { pathname } = request.nextUrl;
if (isPublic(pathname)) {
return securityHeaders();
}
const sessionCookie = getSessionCookie(request);
if (!sessionCookie) {
const url = request.nextUrl.clone();
url.pathname = "/sign-in";
return NextResponse.redirect(url);
}
return securityHeaders();
};
export default proxy;
export const config = {
matcher: [
"/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
"/(api|trpc)(.*)",
],
};