new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Supabase · Edge Functions · all subjects

edge functions/cli

91 notes in this subject, read out of this brain and free to use. This is page 1 of 2.

Create Edge Function with supabase functions new

Create a new Edge Function by running `supabase functions new <function_name>`. This creates a new function directory with an `index.ts` file where the function code is added.

Deploy Edge Function with supabase functions deploy

Deploy an Edge Function to a hosted Supabase project using `supabase functions deploy <function_name>`. Use the `--no-verify-jwt` flag if JWT verification should be disabled. First run `supabase link` to connect to a hosted project, then deploy and set secrets with `supabase secrets set --env-file supabase/.env`.

Local development with supabase functions serve

Use the Supabase CLI command 'supabase functions serve' to run a local runtime similar to production for faster iteration and testing.

Edge Functions deployment methods

Edge Functions can be deployed via Supabase Dashboard, CLI, or MCP.

Configure verify_jwt flag in supabase/config.toml

Set the verify_jwt flag per function in supabase/config.toml using the syntax [functions.function-name] followed by verify_jwt = false (or true). For example, to disable verify_jwt for a stripe-webhook function, use: [functions.stripe-webhook] verify_jwt = false

Deployment: write function and run CLI command

To deploy an edge function, write the function code in your local Supabase project in a file like supabase/functions/apply-filter/index.ts, then run the command 'supabase functions deploy apply-filter' via the Supabase CLI.

ESZip format: bundling for deployment

The Supabase CLI bundles the function and its dependencies into an ESZip file, a compact format created by Deno that includes a complete module graph for quick loading and execution. The bundled ESZip file is uploaded to Supabase's backend.

Function deployment generates unique URL

After deployment, Supabase generates a unique URL for the function, making it accessible globally. Once deployed, the function is ready for invocation from anywhere, with Supabase handling scaling and availability.

Background tasks do not run locally by default

When testing Edge Functions locally with Supabase CLI, instances are terminated automatically after a request is completed. This prevents background tasks from running to completion.

Configure edge_runtime policy for local background task testing

To test background tasks locally, update the supabase/config.toml file with the following settings: ```toml [edge_runtime] policy = "per_worker" ``` This allows background tasks to run to completion during local testing.

Deploy function to production

Deploy the function with: supabase functions deploy --no-verify-jwt

CLI version for Edge Function debugging support

The Supabase CLI version 1.171.0 and later supports debugging Edge Functions via the v8 inspector protocol, enabling debugging through Chrome DevTools and other Chromium-based browsers.

Chrome DevTools inspect protocol port for Edge Functions

The Supabase CLI uses port 8083 on localhost (127.0.0.1:8083) for the v8 inspector protocol when debugging Edge Functions with Chrome DevTools.

Debug Edge Function by sending request and inspecting in DevTools

After configuring Chrome DevTools for Edge Function debugging, send a request to the function running locally (via curl, Postman, or similar). The DevTools window will pause script execution at the first line. Navigate to the 'Sources' tab, then to 'file://' > 'home/deno/functions/<your-function-name>/index.ts' to view the function code. Use DevTools to set breakpoints and inspect execution.

Configure Chrome DevTools for Edge Function debugging

To debug Edge Functions with Chrome DevTools: (1) Navigate to chrome://inspect in Chrome browser. (2) Click the 'Configure...' button next to the Discover network targets checkbox. (3) Enter '127.0.0.1:8083' in the Target discovery settings dialog and click 'Done'. (4) Click 'Open dedicated DevTools for Node' to start listening for incoming requests to edge-runtime.

Serve Edge Functions in inspect mode with breakpoint at first line

Run the command 'supabase functions serve --inspect-mode brk' to serve Edge Functions in inspect mode, which sets a breakpoint at the first line to pause script execution before any code runs.

GitHub Actions deployment for Edge Functions

Deploy Edge Functions using GitHub Actions with the official setup-cli GitHub Action. Example workflow: on push to main branch, use `supabase/setup-cli@v1` action, set environment variables SUPABASE_ACCESS_TOKEN and PROJECT_ID, then run `supabase functions deploy --project-ref $PROJECT_ID`. The full workflow uses `actions/checkout@v4` and `supabase/setup-cli@v1 with version: latest`.

GitLab CI deployment for Edge Functions

Deploy Edge Functions using GitLab CI with node:20 image. Setup stage runs `npm i supabase` with node_modules caching and artifacts. Deploy stage runs `npx supabase init` and `npx supabase functions deploy --debug` with docker:dind service and DOCKER_HOST set to tcp://docker:2375.

Authenticate with Supabase CLI

Log in to the Supabase CLI using the command `supabase login` before deploying functions.

List Supabase projects

Retrieve the list of your Supabase projects and their IDs using the command `supabase projects list`.

Deploy all Edge Functions

Deploy all edge functions in the functions folder using the command `supabase functions deploy`.

Deploy individual Edge Function

Deploy a specific Edge Function by name using the command `supabase functions deploy function-name`, for example `supabase functions deploy hello-world`.

Bitbucket Pipelines deployment for Edge Functions

Deploy Edge Functions using Bitbucket Pipelines with node:20 image. Default pipeline has a setup step that runs `npm i supabase` with node caching, followed by a parallel step with a Functions Deploy job that runs `npx supabase init` and `npx supabase functions deploy --debug` with docker service.

supabase functions serve for developing specific functions

Use supabase functions serve [function-name] to develop a specific function with hot reloading. Your functions run at http://localhost:54321/functions/v1/[function-name]. When you save your file, changes are reflected instantly without waiting. Alternatively, use supabase functions serve without arguments to serve all functions at once.

supabase functions deploy command deploys Edge Functions

Use supabase functions deploy [function-name] to deploy the function to production when you're ready.

supabase start command spins up entire Supabase stack

The supabase start command spins up your entire Supabase stack locally: database, auth, storage, and Edge Functions runtime. You develop against the exact same environment you will deploy to.

Multi-root VSCode workspace for distributed Edge Functions development

For development setups involving multiple repositories (Edge Functions in one repo, main app in another) or microservices running in parallel, create an edge-functions.code-workspace file to enable multi-root workspace support in VSCode.

Auto-generate VSCode settings during supabase init

When running supabase init, you can select 'y' when prompted 'Generate VS Code settings for Deno? [y/N]' to automatically generate the necessary VSCode Deno configuration instead of setting it up manually.

VSCode Deno extension configuration for Supabase functions

To enable Deno support in VSCode for Edge Functions, install the Deno extension, then create a .vscode/settings.json file in your project root with the configuration: {"deno.enablePaths": ["./supabase/functions"], "deno.importMap": "./supabase/functions/deno.json"}. This enables the Deno language server only for the supabase/functions folder while using VSCode's built-in JavaScript/TypeScript language server for other files.

Configuring Edge Functions with config.toml

Individual function configuration such as JWT verification and import map location can be set via the config.toml file in the [functions.function_name] section.

entrypoint configuration requires Supabase CLI version 1.215.0 or higher

The entrypoint configuration in config.toml is available only in Supabase CLI version 1.215.0 or higher.

Create new Edge Function with CLI

Create a new Edge Function using the CLI command: supabase functions new cloudflare-turnstile. This generates a project structure with an index.ts file.

Deploy Edge Function with --no-verify-jwt flag

When deploying an Edge Function that does not require JWT authentication, use the --no-verify-jwt flag: supabase functions deploy cloudflare-turnstile --no-verify-jwt.

Deploy Discord bot edge function with secret

Deploy a Discord bot edge function using 'supabase functions deploy discord-bot --no-verify-jwt'. After deployment, set the DISCORD_PUBLIC_KEY secret using 'supabase secrets set DISCORD_PUBLIC_KEY=your_public_key'. The function endpoint URL is displayed in the Supabase Dashboard Function details page and must be configured in the Discord Developer Portal as the INTERACTIONS ENDPOINT URL.

Run Discord bot edge function locally

Run a Discord bot edge function locally using 'supabase functions serve discord-bot --no-verify-jwt --env-file ./supabase/.env.local'. This starts a local server on port 54321. To expose it to Discord, use ngrok with 'ngrok http 54321' to create a public URL that can be configured as the Discord interaction endpoint.

Create new Edge Function with CLI

To create a new Edge Function locally, run `supabase functions new <function-name>`.

GitHub Actions workflow to deploy Edge Functions

Example GitHub Actions workflow file `deploy.yaml` that deploys Supabase Edge Functions: The workflow triggers on push to the main branch or via workflow_dispatch. It uses `actions/checkout@v4` to checkout code, `supabase/setup-cli@v1` with version `latest` to set up the CLI, then runs `supabase functions deploy --project-ref $PROJECT_ID`. Environment variables `SUPABASE_ACCESS_TOKEN` and `PROJECT_ID` must be provided. The job runs on `ubuntu-latest`.

Deploy all Edge Functions with a single CLI command

Since Supabase CLI v1.62.0, you can deploy all Edge Functions with a single command: `supabase functions deploy --project-ref $PROJECT_ID`. Individual function configuration such as JWT verification and import map location can be set via the `config.toml` file.

Linking local project to Supabase account

Run supabase link to connect a local Supabase project to your hosted Supabase account.

Creating a new Edge Function with CLI

Run supabase functions new function-name to create a new Edge Function. The CLI will prompt to generate VS Code settings for Deno; select 'y' if using VS Code or Cursor.

Deploying secrets to Supabase

Run supabase secrets set --env-file supabase/functions/.env to deploy secrets from a local .env file to your hosted Supabase project.

Local Supabase project initialization

Run supabase init to create a new local Supabase project. Run supabase start to start the local stack, and supabase functions serve to start the function development server.

Pushing local storage buckets to hosted project

Run supabase seed buckets --linked to push storage buckets configured in config.toml to your linked hosted Supabase project.

Deploying Edge Function to Supabase

Run supabase functions deploy to deploy all Edge Functions to your hosted Supabase project.

Test Edge Function locally with supabase functions serve

To test an Edge Function locally, run: supabase start followed by supabase functions serve --no-verify-jwt. This allows testing without JWT verification enabled.

Create image manipulation Edge Function with CLI

To create a new Edge Function for image manipulation, run the command: supabase functions new image-blur

Deploy Edge Function to hosted project

To deploy an Edge Function to a hosted Supabase project, run: supabase link followed by supabase functions deploy image-blur (where image-blur is the function name).

Apply database migrations with supabase db push

To apply pending database migrations to your Supabase project, run the command `supabase db push`. This executes all migration files in the `supabase/migrations` directory that have not yet been applied.

Link local Supabase project to remote with supabase link

To connect a local Supabase project to a remote Supabase account and project, run the command `supabase link`. This allows you to deploy functions, push database migrations, and manage secrets for the remote project.

Initialize local Supabase project with supabase init

To create a new local Supabase project directory structure, run the command `supabase init`. This sets up the basic directory structure including `supabase/migrations` and `supabase/functions` directories.

Create Edge Function with supabase functions new

To create a new Edge Function, run the command `supabase functions new <function-name>`. For example, `supabase functions new scribe-bot` creates a new function named scribe-bot. When using VS Code or Cursor, select 'y' when prompted to generate VS Code settings for Deno.

Initialize database migrations with supabase migrations new

To create a new database migration file in Supabase, run the command `supabase migrations new <migration-name>`. This creates a new SQL file in the `supabase/migrations` directory with a timestamp prefix. Edit the file to add the SQL statements you want to run.

Deploy FCM edge function

To deploy a Firebase Cloud Messaging edge function: run 'supabase link' to link the local project to a remote Supabase project, then run 'supabase functions deploy push --no-verify-jwt'. The service-account.json file must be saved in the supabase/functions directory.

Deploy Expo edge function with secrets

To deploy an Expo push notification edge function: first run 'supabase functions deploy push', then run 'supabase secrets set --env-file .env.local' to set the EXPO_ACCESS_TOKEN secret. The token is generated from Expo Access Token Settings with 'Enhanced Security for Push Notifications' toggled on.

supabase functions new command

To create a new edge function, run 'supabase functions new <function-name>' after initializing Supabase with 'supabase init'. This creates the function directory and index.ts file.

Supabase project setup for push notifications

Initial Supabase setup: create a new project at https://database.new, link the project with 'supabase link --project-ref your-supabase-project-ref', start Supabase locally with 'supabase start', and push the schema with 'supabase db push' where the schema is defined in supabase/migrations directory.

Deploy Edge Functions with supabase functions deploy

Deploy an Edge Function to Supabase using `supabase functions deploy <function-name> --no-verify-jwt`. The `--no-verify-jwt` flag allows the function to accept both JWT tokens and secret keys.

Serve Edge Functions locally with supabase functions serve

Run `supabase functions serve --no-verify-jwt --env-file .env` to serve Edge Functions locally. The `--no-verify-jwt` flag disables JWT verification for testing, and `--env-file .env` loads environment variables from the specified file.

Test Edge Functions locally with curl using apikey header

Test local Edge Functions by sending a POST request with the `apikey` header containing your Supabase secret key. For example: `curl -i --request POST 'http://localhost:54321/functions/v1/<function-name>' --header 'apikey: <SUPABASE_SECRET_KEY>'`

Serve Edge Functions locally

Run Edge Functions locally using `supabase functions serve --no-verify-jwt` after starting the local development environment with `supabase start`.

Give your agent this brain