Browse Source

fix(api): add missing corsHeaders variable in api function

The api function has a special structure with OPTIONS handled outside
wrapHandler. Need to declare corsHeaders in the outer scope so it's
available inside the wrapped handler.

Fixes 500 errors on all /api/* endpoints.
Fszontagh 4 months ago
parent
commit
db65e4acfa
1 changed files with 4 additions and 1 deletions
  1. 4 1
      supabase/functions/api/index.ts

+ 4 - 1
supabase/functions/api/index.ts

@@ -7,9 +7,12 @@ import { getCorsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts';
 
 // Handle OPTIONS requests BEFORE wrapping with error handler to avoid timeouts
 serve(async (req) => {
+  const origin = req.headers.get('Origin') || undefined;
+  const corsHeaders = getCorsHeaders(origin, ['PUT', 'DELETE']);
+
   // Fast-path for OPTIONS requests
   if (req.method === 'OPTIONS') {
-    return handleCorsPreflightRequest(['PUT', 'DELETE'])
+    return handleCorsPreflightRequest(origin, ['PUT', 'DELETE'])
   }
 
   // Wrap all other requests with error handler