Skip to main content

expressWebhook()

简化了在你的 Express.js 服务器中设置 Lambda Webhook 的过程。有关在 Next.js 应用中执行相同操作,请参阅 pagesRouterWebhook()appRouterWebhook()

🌐 Simplifies the process of setting up a Lambda Webhook in your Express.js server. See pagesRouterWebhook() and appRouterWebhook() for doing the same with Next.js apps.

应用编程接口

🌐 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

在 Express.js 服务器中设置 webhook 端点。

🌐 Setting up a webhook endpoint in an Express.js server.

server.js
import {expressWebhook} from '@remotion/lambda/client'; const handler = expressWebhook({ 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'), }) router.post("/webhook", jsonParser, handler); router.options("/webhook", jsonParser, handler);

有关详细示例,请参见 Webhooks

🌐 See Webhooks for a detailed example.

另请参阅

🌐 See also