From 8c96d8be272d3ef63d98015a722b4a5e9b43a2fa Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Mon, 29 May 2023 15:58:49 +0800 Subject: [PATCH] feat(self-host): use `/functions/v1` for Edge Functions --- docker/.env.example | 5 +++-- docker/docker-compose.yml | 7 +++---- docker/volumes/api/kong.yml | 13 +++++++++++++ docker/volumes/functions/hello/index.ts | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 docker/volumes/functions/hello/index.ts diff --git a/docker/.env.example b/docker/.env.example index 17bb463705f..21304c2557b 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -82,7 +82,8 @@ IMGPROXY_ENABLE_WEBP_DETECTION=true ############ # Functions - Configuration for Functions ############ -FUNCTIONS_HTTP_PORT=9002 +# NOTE: VERIFY_JWT applies to all functions. Per-function VERIFY_JWT is not supported yet. +FUNCTIONS_VERIFY_JWT=false ############ # Logs - Configuration for Logflare @@ -101,4 +102,4 @@ VECTOR_API_PORT=9001 # Google Cloud Project details GOOGLE_PROJECT_ID=GOOGLE_PROJECT_ID -GOOGLE_PROJECT_NUMBER=GOOGLE_PROJECT_NUMBER \ No newline at end of file +GOOGLE_PROJECT_NUMBER=GOOGLE_PROJECT_NUMBER diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 29c790d899d..3e28b3acdc4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -250,10 +250,9 @@ services: SUPABASE_URL: http://kong:8000 SUPABASE_ANON_KEY: ${ANON_KEY} SUPABASE_SERVICE_ROLE_KEY: ${SERVICE_ROLE_KEY} - SUPABASE_DB_URL: postgresql://postgres:${POSTGRES_PASSWORD}@{POSTGRES_DB}:${POSTGRES_PORT}/${POSTGRES_DB}" - VERIFY_JWT: "false" - ports: - - ${FUNCTIONS_HTTP_PORT}:9000/tcp + SUPABASE_DB_URL: postgresql://postgres:${POSTGRES_PASSWORD}@{POSTGRES_DB}:${POSTGRES_PORT}/${POSTGRES_DB} + # TODO: Allow configuring VERIFY_JWT per function. This PR might help: https://github.com/supabase/cli/pull/786 + VERIFY_JWT: "${FUNCTIONS_VERIFY_JWT}" volumes: - ./volumes/functions:/home/deno/functions:Z command: diff --git a/docker/volumes/api/kong.yml b/docker/volumes/api/kong.yml index eb1a079eb27..ca90a29a3e4 100644 --- a/docker/volumes/api/kong.yml +++ b/docker/volumes/api/kong.yml @@ -153,6 +153,19 @@ services: - /storage/v1/ plugins: - name: cors + + ## Edge Functions routes + - name: functions-v1 + _comment: 'Edge Functions: /functions/v1/* -> http://functions:9000/*' + url: http://functions:9000/ + routes: + - name: functions-v1-all + strip_path: true + paths: + - /functions/v1/ + plugins: + - name: cors + ## Analytics routes - name: analytics-v1 _comment: 'Analytics: /analytics/v1/* -> http://logflare:4000/*' diff --git a/docker/volumes/functions/hello/index.ts b/docker/volumes/functions/hello/index.ts new file mode 100644 index 00000000000..f1e20b90e01 --- /dev/null +++ b/docker/volumes/functions/hello/index.ts @@ -0,0 +1,16 @@ +// 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. + +import { serve } from "https://deno.land/std@0.177.1/http/server.ts" + +serve(async () => { + return new Response( + `"Hello from Edge Functions!"`, + { headers: { "Content-Type": "application/json" } }, + ) +}) + +// To invoke: +// curl 'http://localhost:/functions/v1/hello' \ +// --header 'Authorization: Bearer '