Documentation Edge functions
Edge functions
CloudCode doesn't host or deploy serverless functions for your app. Files under supabase/functions/ in your project are ordinary files, and saving them doesn't deploy anything. You can write Supabase Edge Functions in CloudCode (or have the agent write them), push the project to GitHub, and deploy them with the Supabase CLI.
Anatomy of an edge function
typescript
// supabase/functions/my-function/index.ts
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
};
Deno.serve(async (req) => {
if (req.method === "OPTIONS") {
return new Response("ok", { headers: corsHeaders });
}
const { name } = await req.json();
const secretKey = Deno.env.get("MY_SECRET_KEY");
// ... call external APIs, query the database, etc.
return new Response(JSON.stringify({ message: `Hello ${name}` }), {
headers: { ...corsHeaders, "Content-Type": "application/json" },
});
});Deploying and calling it
bash
# On your machine or in CI, after pushing the project to GitHub supabase link --project-ref YOUR-PROJECT-REF supabase secrets set MY_SECRET_KEY=... supabase functions deploy my-function
typescript
import { supabase } from "@/lib/supabase";
const { data, error } = await supabase.functions.invoke("my-function", {
body: { name: "world" },
});Tip
For a small Node.js API, there's another option. An Express server in
index.js, server.js or app.js can go out through the preview toolbar's Deploy dialog as a "Node.js App", which runs as a Vercel serverless function. Environment variables still aren't injected (see Deployment → Environment variables).