Skip to main content

appRouterWebhook()

简化了在使用 App Router 的 Next.js 应用中设置 Lambda Webhook 的过程。有关在使用 Pages Router 的应用中执行相同操作,请参阅 pagesRouterWebhook()

🌐 Simplifies the process of setting up a Lambda Webhook in your Next.js app which is using App Router. Refer to pagesRouterWebhook() for doing the same in apps using Pages Router.

应用编程接口

🌐 API

该函数接受一个包含六个键值对的对象:

🌐 The function accepts an object with six key-value pairs:

secret

你的 webhook 密钥,必须是 string

🌐 Your webhook secret, must be a string

testing

是否允许旨在测试端点的请求,在使用 Webhooks 页面 的 Webhook 端点测试工具时非常有用。应为 boolean

🌐 Whether or not to allow requests intending to test the endpoint, useful while using Webhook endpoint tester on Webhooks Page. Should be a boolean.

extraHeaders

向传出的响应添加你自己的自定义头。提供键值对,其中键和值都是字符串。

🌐 Add your own custom headers to the outgoing response. Provide key-value pairs where both the key and value are strings.

onSuccess()

当传入请求指示事件成功时,会调用一个函数,并将 WebhookSuccessPayload 对象作为参数传入。

🌐 A function that is called with a WebhookSuccessPayload object as an argument when the incoming request indicates a successful event.

onError()

当传入的请求指示出现错误时,会使用 WebhookErrorPayload 对象作为参数调用的函数。

🌐 A function that is called with a WebhookErrorPayload object as an argument when the incoming request indicates an error.

onTimeout()

当传入请求表示超时时,会使用 WebhookTimeoutPayload 对象作为参数调用的函数。

🌐 A function that is called with a WebhookTimeoutPayload object as an argument when the incoming request indicates a timeout.

示例

🌐 Example

在使用 App Router 的 Next.js 应用中设置一个 webhook 端点。这将监听端点:mydomain.com/api

🌐 Setting up a webhook endpoint in a Next.js app which uses App Router. This will listen on the endpoint: mydomain.com/api

app/api/route.ts
import {appRouterWebhook} from '@remotion/lambda/client'; export const POST = appRouterWebhook({ secret: 'mysecret', testing: true, extraHeaders: { region: 'south-asia', }, onSuccess: () => console.log('Rendering Completed Successfully'), onError: () => console.log('Something went wrong while rendering'), onTimeout: () => console.log('Timeout occured while rendering'), }); export const OPTIONS = POST;

请参见 Webhooks 了解 Express 示例。

🌐 See Webhooks for an Express example.

另请参阅

🌐 See also