diff --git a/supabase/README.md b/supabase/README.md new file mode 100644 index 000000000..509235ad2 --- /dev/null +++ b/supabase/README.md @@ -0,0 +1,22 @@ +# supabase + +this folder will contain one or more supabase edge functions to talk with the database + +## usage + +``` +pnpx supabase functions serve --no-verify-jwt # serve locally, requires docker +pnpx supabase functions deploy # deploy function(s) +``` + +## test + +when running locally, you can test an endpoint with curl: + +```sh +curl -L -X POST 'http://127.0.0.1:54321/functions/v1/hello-world' \ + -H 'Content-Type: application/json' \ + --data '{"foo":"bar"}' +``` + + diff --git a/supabase/config.toml b/supabase/config.toml index cae44fdba..cd5854abf 100644 --- a/supabase/config.toml +++ b/supabase/config.toml @@ -313,3 +313,14 @@ s3_region = "env(S3_REGION)" s3_access_key = "env(S3_ACCESS_KEY)" # Configures AWS_SECRET_ACCESS_KEY for S3 bucket s3_secret_key = "env(S3_SECRET_KEY)" + +[functions.hello-world] +enabled = true +verify_jwt = true +import_map = "./functions/hello-world/deno.json" +# Uncomment to specify a custom file path to the entrypoint. +# Supported file extensions are: .ts, .js, .mjs, .jsx, .tsx +entrypoint = "./functions/hello-world/index.ts" +# Specifies static files to be bundled with the function. Supports glob patterns. +# For example, if you want to serve static HTML pages in your function: +# static_files = [ "./functions/hello-world/*.html" ] diff --git a/supabase/functions/hello-world/.npmrc b/supabase/functions/hello-world/.npmrc new file mode 100644 index 000000000..48c638863 --- /dev/null +++ b/supabase/functions/hello-world/.npmrc @@ -0,0 +1,3 @@ +# Configuration for private npm package dependencies +# For more information on using private registries with Edge Functions, see: +# https://supabase.com/docs/guides/functions/import-maps#importing-from-private-registries diff --git a/supabase/functions/hello-world/deno.json b/supabase/functions/hello-world/deno.json new file mode 100644 index 000000000..f6ca8454c --- /dev/null +++ b/supabase/functions/hello-world/deno.json @@ -0,0 +1,3 @@ +{ + "imports": {} +} diff --git a/supabase/functions/hello-world/index.ts b/supabase/functions/hello-world/index.ts new file mode 100644 index 000000000..df7c0e0dc --- /dev/null +++ b/supabase/functions/hello-world/index.ts @@ -0,0 +1,32 @@ +// Follow this setup guide to integrate the Deno language server with your editor: +// https://deno.land/manual/getting_started/setup_your_environment +// This enables autocomplete, go to definition, etc. + +// Setup type definitions for built-in Supabase Runtime APIs +import "jsr:@supabase/functions-js/edge-runtime.d.ts" + +console.log("Hello from Functions!") + +Deno.serve(async (req) => { + const { name } = await req.json() + const data = { + message: `Hello ${name}!`, + } + + return new Response( + JSON.stringify(data), + { headers: { "Content-Type": "application/json" } }, + ) +}) + +/* To invoke locally: + + 1. Run `supabase start` (see: https://supabase.com/docs/reference/cli/supabase-start) + 2. Make an HTTP request: + + curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/hello-world' \ + --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \ + --header 'Content-Type: application/json' \ + --data '{"name":"Functions"}' + +*/