@@ -9,43 +9,37 @@ import {
99} from '@/lib/middleware'
1010
1111export async function proxy ( request : NextRequest ) {
12- // Apply rate limiting for API routes
12+ // 1. Rate limit API routes (100 req/min per IP per endpoint)
1313 const rateLimitResult = rateLimitMiddleware ( request )
1414 if ( rateLimitResult ) return rateLimitResult
1515
16- // Create Supabase client and refresh auth token
16+ // 2. Create Supabase client and refresh auth token
1717 const { supabaseResponse, user } = await createSupabaseMiddlewareClient ( request )
1818
19- // Create middleware context
2019 const context : MiddlewareContext = {
2120 request,
2221 response : supabaseResponse ,
2322 user,
2423 }
2524
26- // Check API authentication
25+ // 3. API Authentication check
2726 const apiAuthResult = apiAuthMiddleware ( context )
28- if ( apiAuthResult ) return apiAuthResult
27+ if ( apiAuthResult ) return addSecurityHeaders ( apiAuthResult )
2928
30- // Check page authentication and redirects
29+ // 4. Page Authentication and redirects
3130 const authResult = authMiddleware ( context )
32- if ( authResult ) return authResult
31+ if ( authResult ) return addSecurityHeaders ( authResult )
3332
34- // Add security headers to response
35- addSecurityHeaders ( supabaseResponse )
36-
37- return supabaseResponse
33+ // 5. Add security headers to the main response
34+ return addSecurityHeaders ( supabaseResponse )
3835}
3936
4037export const config = {
4138 matcher : [
4239 /*
43- * Match all request paths except for the ones starting with:
44- * - _next/static (static files)
45- * - _next/image (image optimization files)
46- * - favicon.ico (favicon file)
47- * - public (public files)
40+ * Match all routes except static files, _next internals, and public assets
41+ * This includes sw.js and manifest.json to ensure PWA works correctly
4842 */
49- '/((?!_next/static|_next/image|favicon.ico|public| images|. *\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)' ,
43+ '/((?!_next/static|_next/image|favicon.ico|images|icons|sw.js|manifest.json|. *\\.(?:svg|png|jpg|jpeg|gif|webp|ico )$).*)' ,
5044 ] ,
5145}
0 commit comments