MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / proxy

Function proxy

apps/web/proxy.ts:23–50  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

21}
22
23export async function proxy(request: NextRequest) {
24 const { pathname } = request.nextUrl;
25 if (isPublicPath(pathname)) {
26 return NextResponse.next();
27 }
28
29 const config = getWebAuthConfig();
30 const sessionCookie = request.cookies.get(config.cookieName)?.value;
31 const authenticated = await isAuthenticatedCookie(sessionCookie);
32
33 if (authenticated) {
34 return NextResponse.next();
35 }
36
37 if (isApiPath(pathname)) {
38 return NextResponse.json(
39 {
40 error: config.enabled ? 'Unauthorized' : 'Web auth is not configured',
41 },
42 { status: 401 },
43 );
44 }
45
46 if (!config.enabled) {
47 return redirectTo(request, '/login', 307, '?error=config');
48 }
49 return redirectTo(request, '/login');
50}
51
52export const config = {
53 matcher: ['/((?!_next/static|_next/image).*)'],

Callers

nothing calls this directly

Calls 6

getWebAuthConfigFunction · 0.90
isAuthenticatedCookieFunction · 0.90
isPublicPathFunction · 0.85
isApiPathFunction · 0.85
redirectToFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected