Create, serve locally, deploy and manage Edge Functions and their secrets with the CLI.
stitchdb functions new send-email # stitchdb/functions/send-email/index.ts
stitchdb functions serve # local, live reload
stitchdb functions deploy send-email
stitchdb functions deploy # every function#Serve locally
functions serve runs every folder in stitchdb/functions at http://127.0.0.1:54321/functions/v1/<name> and follows their logs. Each function runs in its own Deno process that restarts when you save a file. Functions get STITCHDB_URL, STITCHDB_ANON_KEY, STITCHDB_SERVICE_ROLE_KEY and STITCHDB_DB_URL for the local project, plus the secrets in stitchdb/functions/.env.
curl -i http://127.0.0.1:54321/functions/v1/send-email \
-H 'Authorization: Bearer <local anon key>' -d '{"to":"[email protected]"}'#Deploy
Each deploy uploads the function's folder as a new version (the previous 20 are kept, see Deploy with the API). Imports of ../_shared/… are bundled with the function. A deno.json or import_map.json in the folder is used as the import map.
Calls need a valid JWT (anon key or a user's token) unless you turn that off, for example for webhooks:
# stitchdb/config.toml
[functions.stripe-webhook]
verify_jwt = falseor per deploy: stitchdb functions deploy stripe-webhook --no-verify-jwt.
| Command | Does |
|---|---|
stitchdb functions list | Deployed functions, versions and JWT setting |
stitchdb functions download <name> | The deployed code into stitchdb/functions/<name> |
stitchdb functions delete <name> | Deletes the function (its URL stops working) |
#Secrets
stitchdb secrets set STRIPE_KEY=sk_live_… RESEND_KEY=re_…
stitchdb secrets set --env-file .env.production
stitchdb secrets list
stitchdb secrets unset STRIPE_KEYSecrets are environment variables for every function of the project (Deno.env.get('STRIPE_KEY')). Values are write-only: secrets list shows names and digests. See Environment and secrets.