Edge functions cors problem

Hey guys I'm trying to run the hello-world edge function example locally, but I'm having this cors error: No 'Access-Control-Allow-Origin' header is present on the requested resource. This is how I'm setting up the function:

import { serve } from "https://deno.land/std@0.131.0/http/server.ts";

export const corsHeaders = {
  "Access-Control-Allow-Origin": "http://localhost:5173", // even with * I have the problem
  "Access-Control-Allow-Headers": "*",
  "Access-Control-Allow-Methods": "*",
};

serve(async (req) => {
  if (req.method === "OPTIONS") {
    return new Response("ok", { headers: corsHeaders });
  }

  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 I'm calling it in my client on the browser

 const data = await supabase.functions.invoke('hello-world', {
  headers: {
    'Access-Control-Allow-Origin': 'http://localhost:54321', // here I'm adding the header so it should be present on the request? 
  },
})



I put the browser request screenshot here also, probably I'm doing something wrong but I can't understand why.
unknown.png
Was this page helpful?