Add static files to Edge Functions

Jan 15, 2025

Supabase CLI 2.7.0 adds support for bundling Edge Functions with static files.

You can access bundled files via Deno's file-system APIs. Here's an example function that serves a PDF file.


_14
import fs from 'node:fs'; // This should be the first import to prevent other modules to trying to use their own polyfills.
_14
_14
_14
Deno.serve(async () => {
_14
return new Response(
_14
await Deno.readFile("./my-book.pdf"),
_14
{
_14
headers: {
_14
"Content-Type": "application/pdf",
_14
"Content-Disposition": 'attachment; filename="my-book.pdf"',
_14
},
_14
},
_14
);
_14
});

Use cases#

  • Use custom Wasm modules in your Edge Functions (check this guide for more details on how to write & use wasm modules in Edge Functions)
  • Create paywalls for serving digital content like ebooks
  • HTML email templates for sending emails using Edge Functions

How to configure#

You will need to add static files to the function's directory to bundle them. Then, in the supabase/config.toml file for the project, add these lines:


_10
[functions.buy-book]
_10
static_files = [ "./functions/buy-book/my-book.pdf" ]

You can specify an array of files or use a glob pattern (eg: "./functions/email-templates/*.html")

Check the CLI configuration reference for more details: https://supabase.com/docs/guides/local-development/cli/config#functions.function_name.static_files

Note: This feature is currently not available with branching and will be added with the next stable release of the CLI.

Build in a weekend, scale to millions