Supabase Edge Function returns 404 NOT_FOUND on the CORS preflight

By Abheesht Tripathi · Published

Response to preflight request doesn't pass access control check: It does not have HTTP ok status.  (OPTIONS …/functions/v1/my-function → 404, sb-error-code: NOT_FOUND)

What it means

The 404 comes from Supabase's Functions gateway, before your code runs. Usually no function with that name is registered on the project in the URL; Supabase also documents NOT_FOUND when a function isn't available in a region yet (redeploy and wait), and NOT_FOUND_FUNCTION_BLOB returns the same body. The sb-error-code response header tells them apart. Because your function never ran, your CORS headers never got sent, and the browser reports it as a CORS error. Changing CORS code won't fix it.

Prove it in one minute

# your function
curl -i -X OPTIONS https://<project-ref>.supabase.co/functions/v1/my-function

# a name that surely doesn't exist
curl -i -X OPTIONS https://<project-ref>.supabase.co/functions/v1/does-not-exist-123

If both return the same 404, the gateway doesn't know your function at that address.

The usual causes

  1. Name mismatch. The function name is the folder name under supabase/functions/. capture-paypal-order, capture_paypal_order and capturePaypalOrder are three different functions.
  2. Wrong project. Deployed to staging, but the app's SUPABASE_URL points at production (or the other way round). The project ref in the URL decides where the request goes.
  3. Renamed or deleted after the frontend was built, and the app still calls the old name.

List what is actually deployed on the project your app calls:

supabase functions list --project-ref <project-ref>

If a test from the dashboard works but the browser gets 404, compare the exact URL in the browser's network tab with the names in that list.

Once the function is found: a CORS handler that works

const cors = {
  'Access-Control-Allow-Origin': 'https://your-app.com',
  'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
  'Access-Control-Allow-Methods': 'POST, OPTIONS',
};

Deno.serve(async (req) => {
  if (req.method === 'OPTIONS') return new Response('ok', { headers: cors });
  const data = { ok: true };
  return new Response(JSON.stringify(data), {
    headers: { ...cors, 'Content-Type': 'application/json' },
  });
});

Add the CORS headers to every response, including errors, or the browser hides the real error behind a CORS message again.

Related guides

More in Edge Functions, webhooks and APIs · all guides