Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Supabase 11 min read How-to mediumAdept

Executing Dynamic JavaScript Code on Supabase with Edge Functions

Supabase Edge Functions can execute arbitrary JavaScript sent in the request body by wrapping it in an async `new Function()` that receives a preconfigured service-role Supabase client, so business logic can change without redeploying. SQL helpers built on the pgsql-http extension let Postgres call the function directly. `edge.http_request` wraps the HTTP call, `edge.edge_wrapper` adds retries with backoff delays and rotation across allowed regions via an `x-region` header, `edge.get_secret` reads the service-role key from Vault, and `edge.exec` ties them together. Access is limited to callers presenting the service_role key, since the function would otherwise be an open remote code execution endpoint.

Assumes: PL/pgSQL functionsSupabase basicsJavaScript async/await

Related posts

  • Edge Functions are now available in Supabase

    Supabase easyNovice

    Supabase Edge Functions run TypeScript globally on the Deno runtime via Deno Deploy across 30+ data centers. Supabase chose functions-as-a-service over containers for simpler developer experience and faster start-ups, and global deployment over a single region, with Postgres-colocated Database Functions covering DB-heavy work. Requests pass through a Relay gateway that verifies JWTs, rate-limits and logs, then maps function metadata to a Deno Deploy deployment ID. Cold starts fetch code and secrets from Supabase, and logs flow through Logflare into the dashboard. Functions are POST-only, and static hosting is ruled out after phishing abuse on Supabase Storage got the domain denylisted.

  • Introducing @supabase/server

    Supabase mediumAdept

    @supabase/server, now in public beta, replaces the repeated setup code found across 25,000 analyzed Edge Functions: client creation, JWT verification, claims parsing, CORS and auth wiring. A withSupabase wrapper (or createSupabaseContext for custom error handling) takes a declarative auth mode such as 'user', 'none', 'secret', 'publishable' or a combination. It rejects unauthorized requests before the handler runs and supplies a context with a user-scoped RLS client, a service-role admin client and verified claims. It handles the new asymmetric JWT signing keys and API keys internally, so migrating needs no jose or JWKS setup. It returns a standard Request-to-Response handler that runs on Edge Functions, Vercel, Cloudflare Workers, Bun and Hono, and exposes lower-level primitives for per-route auth.

  • Edge Functions: Node and native npm compatibility

    Supabase mediumAdept

    Supabase Edge Functions now natively support npm modules (via `npm:` imports) and Node built-in APIs, so existing Node apps using Express, node-postgres and Drizzle can migrate with minimal changes. Under the hood, the open-source Deno-based Supabase Edge Runtime serializes each function's module graph into a single eszip at deploy time and loads all modules from it in the hosted, local and self-hosted environments alike. This avoids fetch latency, dependency conflicts with locally installed packages, and bugs such as failures when a deno.lock file is present. The release also adds regional invocation via an `x-region` header, CPU/memory and status-code metrics in the dashboard, and error tracking through Sentry's Deno SDK.

  • Persistent Storage and 97% Faster Cold Starts for Edge Functions

    Supabase mediumAdept

    Supabase Edge Functions can now mount any S3-compatible bucket, including Supabase Storage, as a POSIX-like directory under /s3, configured through four S3FS_* environment secrets. One example reads a SQLite backup from S3 into memory and pushes aggregates to Postgres. Cold starts improved after workers still doing initial script evaluation were moved off the shared cooperatively scheduled Tokio thread pool onto a dedicated blocking pool, so heavy startup work no longer stalls neighbouring functions. In the benchmark, average boot time fell from 870 ms to 42 ms and P99 from 15 s to 460 ms. Synchronous file APIs are now allowed during initial script evaluation only, not inside request handlers or timers.

  • Supabase Edge Runtime: Self-hosted Deno Functions

    Supabase mediumAdept

    Supabase Edge Runtime is an MIT-licensed, Rust-based web server built on deno_core that self-hosts Deno Edge Functions (TypeScript, JavaScript, WASM) without code changes. A hyper HTTP server forwards requests to a Main Worker V8 isolate, which can create sandboxed User Worker isolates with restricted APIs and configurable memory (default 150 MB) and wall-clock (default 60s) limits. It also powers `supabase functions serve` for serving all functions locally with hot reload and Deno Deploy API parity, and a Fly.io walkthrough shows how to deploy it. Planned uses include replacing Kong as an API gateway, scheduled functions, and custom platform globals.

The quest for software engineering knowledge.

Look:
Layout: