Skip to content
Edge Functions

功能配置

Configure individual function behavior. Customize authentication, dependencies, and other settings per function.

配置 #

🌐 Configuration

默认情况下,你所有的 Edge Functions 都有相同的设置。不过在实际应用中,你可能需要不同函数之间有不同的行为。

🌐 By default, all your Edge Functions have the same settings. In real applications, however, you might need different behaviors between functions.

例如:

🌐 For example:

  • Stripe 网络钩子 需要可以公开访问(Stripe 没有你的用户令牌)
  • 用户资料 API 应该需要身份验证
  • 有些功能 可能需要特殊的依赖或不同的文件类型

要启用这些每个函数的规则,在你的项目根目录下创建 supabase/config.toml:

🌐 To enable these per-function rules, create supabase/config.toml in your project root:

1
# Disables authentication for the Stripe webhook.
2
[functions.stripe-webhook]
3
verify_jwt = false
4
5
# Custom dependencies for this specific function
6
[functions.image-processor]
7
import_map = './functions/image-processor/import_map.json'
8
9
# Custom entrypoint for legacy function using JavaScript
10
[functions.legacy-processor]
11
entrypoint = './functions/legacy-processor/index.js

这个配置告诉 Supabase,stripe-webhook 函数不需要有效的 JWT,image-processor 函数使用自定义导入映射,而 legacy-processor 使用自定义入口点。

🌐 This configuration tell Supabase that the stripe-webhook function doesn't require a valid JWT, the image-processor function uses a custom import map, and legacy-processor uses a custom entrypoint.

你只需设定这些规则一次,以后就不用再担心它们了。部署你的功能时,可以放心,它们的安全性和行为完全符合每个端点的需求。

🌐 You set these rules once and never worry about them again. Deploy your functions knowing that the security and behavior is exactly what each endpoint needs.


跳过授权检查 #

🌐 Skipping authorization checks

默认情况下,Edge Functions 需要在授权头中有一个有效的 JWT。如果你想在不进行授权检查的情况下使用 Edge Functions(通常用于 Stripe webhooks),你可以在你的 config.toml 中进行配置:

🌐 By default, Edge Functions require a valid JWT in the authorization header. If you want to use Edge Functions without Authorization checks (commonly used for Stripe webhooks), you can configure this in your config.toml:

1
[functions.stripe-webhook]
2
verify_jwt = false

你也可以在本地运行 Edge 函数时传入 --no-verify-jwt 标志:

🌐 You can also pass the --no-verify-jwt flag when serving your Edge Functions locally:

1
supabase functions serve hello-world --no-verify-jwt

自定义入口点 #

🌐 Custom entrypoints

当你创建一个新的 Edge 函数时,它默认会使用 TypeScript。不过,你也可以使用纯 JavaScript 来编写和部署 Edge 函数。

🌐 When you create a new Edge Function, it will use TypeScript by default. However, it is possible to write and deploy Edge Functions using pure JavaScript.

将你的函数保存为一个 JavaScript 文件(例如 index.js),然后更新 supabase/config.toml

🌐 Save your Function as a JavaScript file (e.g. index.js) update the supabase/config.toml :

1
[functions.hello-world]
2
entrypoint = './index.js' # path must be relative to config.toml

你可以使用任何 .ts.js.tsx.jsx.mjs 文件作为函数的入口点。

🌐 You can use any .ts, .js, .tsx, .jsx or .mjs file as the entrypoint for a Function.