I am trying to call a supabase edge function in javascript but I am getting this error:
access to fetch at 'https:/blablala.functions.supabase.co/hello-world' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
This is how the function looks like (default when creating the function):
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
console.log("Hello from Functions!");
serve(async (req) => {
const { name } = await req.json();
const data = {
message: `Hello ${name}!`,
};
return new Response(JSON.stringify(data), {
headers: { "Content-Type": "application/json" },
});
});
and this is how it looks when I try to call it (just like the docs):
import { supabase } from "$lib/supabaseClient";
const functionTest = async () => {
const { data, error } = await supabase.functions.invoke("hello-world", {
body: { name: "Functions" },
}); };
I do not understand what the problem could be since this is just like they did in the docs. and I have no previous experience with edge/cloud functions so I have no idea how I could try to find a solution. I have not found any good recourses online either.