"Failed to send a request to the Edge Function" - but function got invoked

I just started learning supabase. Following edge function got created without jwt verification.
Deno.serve(async () => {
const name = "World"
const data = {
text: `Hello ${name} -|- Welcome to Supabase Functions!`
}
console.log("hello-world function invoked:", data)

return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })
})
Deno.serve(async () => {
const name = "World"
const data = {
text: `Hello ${name} -|- Welcome to Supabase Functions!`
}
console.log("hello-world function invoked:", data)

return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })
})
When i call it from my nextjs frontend like this:
const { data, error: fnError } = await supabaseClient.functions.invoke("hello-world", {});
const { data, error: fnError } = await supabaseClient.functions.invoke("hello-world", {});
The function runs in supabase successfully (2xx statuscode), but the FE tells me "Failed to send a request to the Edge Function" Any ideas why this happens? EDIT: Maybe useful: the OPTIONS call in preflight works, only the actual call to the function breaks When i call the URL manuall i get the expected response
No description
1 Reply
Zhorky
ZhorkyOP3d ago
SOLVED: found this page: https://supabase.com/docs/guides/functions/cors 1. missing the cors 2. missing cors and status in response
CORS (Cross-Origin Resource Sharing) support for Invoking from the ...
Add CORS headers to invoke Edge Functions from the browser.

Did you find this page helpful?