-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
51 lines (43 loc) · 1.4 KB
/
proxy.ts
File metadata and controls
51 lines (43 loc) · 1.4 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
import { NextResponse, type NextRequest } from 'next/server'
import {
createSupabaseMiddlewareClient,
authMiddleware,
apiAuthMiddleware,
addSecurityHeaders,
rateLimitMiddleware,
type MiddlewareContext,
} from '@/lib/middleware'
export async function proxy(request: NextRequest) {
// Apply rate limiting for API routes
const rateLimitResult = rateLimitMiddleware(request)
if (rateLimitResult) return rateLimitResult
// Create Supabase client and refresh auth token
const { supabaseResponse, user } = await createSupabaseMiddlewareClient(request)
// Create middleware context
const context: MiddlewareContext = {
request,
response: supabaseResponse,
user,
}
// Check API authentication
const apiAuthResult = apiAuthMiddleware(context)
if (apiAuthResult) return apiAuthResult
// Check page authentication and redirects
const authResult = authMiddleware(context)
if (authResult) return authResult
// Add security headers to response
addSecurityHeaders(supabaseResponse)
return supabaseResponse
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - public (public files)
*/
'/((?!_next/static|_next/image|favicon.ico|public|images|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
],
}