Browse Source

fix: handle OPTIONS requests before error handler wrapper to prevent timeouts #64

Claude 5 months ago
parent
commit
897439df26
1 changed files with 8 additions and 2 deletions
  1. 8 2
      supabase/functions/api/index.ts

+ 8 - 2
supabase/functions/api/index.ts

@@ -8,11 +8,16 @@ const corsHeaders = {
   'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
   'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
 }
 }
 
 
-serve(wrapHandler('api', async (req) => {
+// Handle OPTIONS requests BEFORE wrapping with error handler to avoid timeouts
+serve(async (req) => {
+  // Fast-path for OPTIONS requests
   if (req.method === 'OPTIONS') {
   if (req.method === 'OPTIONS') {
     return new Response('ok', { headers: corsHeaders })
     return new Response('ok', { headers: corsHeaders })
   }
   }
 
 
+  // Wrap all other requests with error handler
+  return wrapHandler('api', async (req) => {
+
   try {
   try {
     const url = new URL(req.url)
     const url = new URL(req.url)
     const path = url.pathname.replace('/api/', '')
     const path = url.pathname.replace('/api/', '')
@@ -1680,4 +1685,5 @@ serve(wrapHandler('api', async (req) => {
       { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
       { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
     )
     )
   }
   }
-}))
+  })(req)
+})