Skip to content

🎥 Make videos programmatically with React

finish

Jonny Burgera363400bd953
diff --git a/packages/ai-improvements/.jsdoc/approuterwebhook b/packages/ai-improvements/.jsdoc/approuterwebhook
new file mode 100644
index 0000000000..af5a94ac24
--- /dev/null
+++ b/packages/ai-improvements/.jsdoc/approuterwebhook
@@ -0,0 +1,4 @@
+/**
+ * @description Simplifies the process of setting up a Lambda Webhook in your Next.js app which is using App Router.
+ * @see [Documentation](https://www.remotion.dev/docs/lambda/approuterwebhook)
+ */
\ No newline at end of file
diff --git a/packages/ai-improvements/.jsdoc/pagesrouterwebhook b/packages/ai-improvements/.jsdoc/pagesrouterwebhook
new file mode 100644
index 0000000000..85f371ef24
--- /dev/null
+++ b/packages/ai-improvements/.jsdoc/pagesrouterwebhook
@@ -0,0 +1,4 @@
+/**
+ * @description Simplifies the process of setting up a Lambda Webhook in your Next.js app which is using Pages Router.
+ * @see [Documentation](https://www.remotion.dev/docs/lambda/pagesrouterwebhook)
+ */
\ No newline at end of file
diff --git a/packages/docs/components/TableOfContents/lambda.tsx b/packages/docs/components/TableOfContents/lambda.tsx
index 88e9d79324..a34917f2e9 100644
--- a/packages/docs/components/TableOfContents/lambda.tsx
+++ b/packages/docs/components/TableOfContents/lambda.tsx
@@ -1,108 +1,112 @@
-import React from "react";
-import { Grid } from "./Grid";
-import { TOCItem } from "./TOCItem";
+import React from 'react';
+import {Grid} from './Grid';
+import {TOCItem} from './TOCItem';
export const TableOfContents: React.FC = () => {
- return (
- <div>
- <Grid>
- <TOCItem link="/docs/lambda/estimateprice">
- <strong>estimatePrice()</strong>
- <div>Estimate the price of a render</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/deployfunction">
- <strong>deployFunction()</strong>
- <div>Create a new function in AWS Lambda</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/deletefunction">
- <strong>deleteFunction()</strong>
- <div>Delete a function in AWS Lambda</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getfunctioninfo">
- <strong>getFunctionInfo()</strong>
- <div>Gets information about a function</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getfunctions">
- <strong>getFunctions()</strong>
- <div>Lists available Remotion Lambda functions</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getcompositionsonlambda">
- <strong>getCompositionsOnLambda()</strong>
- <div>Gets list of compositions inside a Lambda function</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/deletesite">
- <strong>deleteSite()</strong>
- <div>Delete a bundle from S3</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/deploysite">
- <strong>deploySite()</strong>
- <div>Bundle and upload a site to S3</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getawsclient">
- <strong>getAwsClient()</strong>
- <div>Access the AWS SDK directly</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getregions">
- <strong>getRegions()</strong>
- <div>Get all available regions</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getsites">
- <strong>getSites()</strong>
- <div>Get all available sites</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/downloadmedia">
- <strong>downloadMedia()</strong>
- <div>Download a render artifact from S3</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getuserpolicy">
- <strong>getUserPolicy()</strong>
- <div>Get the policy JSON for your AWS user</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getrolepolicy">
- <strong>getRolePolicy()</strong>
- <div>Get the policy JSON for your AWS role</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getorcreatebucket">
- <strong>getOrCreateBucket()</strong>
- <div>Ensure a Remotion S3 bucket exists</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/getrenderprogress">
- <strong>getRenderProgress()</strong>
- <div>Query the progress of a render</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/presignurl">
- <strong>presignUrl()</strong>
- <div>Make a private file public to those with the link</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/rendermediaonlambda">
- <strong>renderMediaOnLambda()</strong>
- <div>Trigger a video or audio render</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/renderstillonlambda">
- <strong>renderStillOnLambda()</strong>
- <div>Trigger a still render</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/simulatepermissions">
- <strong>simulatePermissions()</strong>
- <div>Ensure permissions are correctly set up</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/speculatefunctionname">
- <strong>speculateFunctionName()</strong>
- <div>Get the lambda function name based on its configuration</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/validatewebhooksignature">
- <strong>validateWebhookSignature()</strong>
- <div>Validate an incoming webhook request is authentic</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/approuterwebhooks">
- <strong>appRouterWebhooks()</strong>
- <div>Handle incoming webhooks specifically for the Next.js app router</div>
- </TOCItem>
- <TOCItem link="/docs/lambda/pagerouterwebhooks">
- <strong>pageRouterWebhooks()</strong>
- <div>Handle incoming webhooks specifically for the Next.js pages router</div>
- </TOCItem>
- </Grid>
- </div>
- );
+ return (
+ <div>
+ <Grid>
+ <TOCItem link="/docs/lambda/estimateprice">
+ <strong>estimatePrice()</strong>
+ <div>Estimate the price of a render</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/deployfunction">
+ <strong>deployFunction()</strong>
+ <div>Create a new function in AWS Lambda</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/deletefunction">
+ <strong>deleteFunction()</strong>
+ <div>Delete a function in AWS Lambda</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getfunctioninfo">
+ <strong>getFunctionInfo()</strong>
+ <div>Gets information about a function</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getfunctions">
+ <strong>getFunctions()</strong>
+ <div>Lists available Remotion Lambda functions</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getcompositionsonlambda">
+ <strong>getCompositionsOnLambda()</strong>
+ <div>Gets list of compositions inside a Lambda function</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/deletesite">
+ <strong>deleteSite()</strong>
+ <div>Delete a bundle from S3</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/deploysite">
+ <strong>deploySite()</strong>
+ <div>Bundle and upload a site to S3</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getawsclient">
+ <strong>getAwsClient()</strong>
+ <div>Access the AWS SDK directly</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getregions">
+ <strong>getRegions()</strong>
+ <div>Get all available regions</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getsites">
+ <strong>getSites()</strong>
+ <div>Get all available sites</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/downloadmedia">
+ <strong>downloadMedia()</strong>
+ <div>Download a render artifact from S3</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getuserpolicy">
+ <strong>getUserPolicy()</strong>
+ <div>Get the policy JSON for your AWS user</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getrolepolicy">
+ <strong>getRolePolicy()</strong>
+ <div>Get the policy JSON for your AWS role</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getorcreatebucket">
+ <strong>getOrCreateBucket()</strong>
+ <div>Ensure a Remotion S3 bucket exists</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/getrenderprogress">
+ <strong>getRenderProgress()</strong>
+ <div>Query the progress of a render</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/presignurl">
+ <strong>presignUrl()</strong>
+ <div>Make a private file public to those with the link</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/rendermediaonlambda">
+ <strong>renderMediaOnLambda()</strong>
+ <div>Trigger a video or audio render</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/renderstillonlambda">
+ <strong>renderStillOnLambda()</strong>
+ <div>Trigger a still render</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/simulatepermissions">
+ <strong>simulatePermissions()</strong>
+ <div>Ensure permissions are correctly set up</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/speculatefunctionname">
+ <strong>speculateFunctionName()</strong>
+ <div>Get the lambda function name based on its configuration</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/validatewebhooksignature">
+ <strong>validateWebhookSignature()</strong>
+ <div>Validate an incoming webhook request is authentic</div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/approuterwebhook">
+ <strong>appRouterWebhook()</strong>
+ <div>
+ Handle incoming webhooks specifically for the Next.js app router
+ </div>
+ </TOCItem>
+ <TOCItem link="/docs/lambda/pagesrouterwebhook">
+ <strong>pagesRouterWebhook()</strong>
+ <div>
+ Handle incoming webhooks specifically for the Next.js pages router
+ </div>
+ </TOCItem>
+ </Grid>
+ </div>
+ );
};
diff --git a/packages/docs/docs/lambda/approuterwebhooks.mdx b/packages/docs/docs/lambda/approuterwebhook.mdx
similarity index 58%
rename from packages/docs/docs/lambda/approuterwebhooks.mdx
rename to packages/docs/docs/lambda/approuterwebhook.mdx
index 6e72fe271d..a8ff9e45cb 100644
--- a/packages/docs/docs/lambda/approuterwebhooks.mdx
+++ b/packages/docs/docs/lambda/approuterwebhook.mdx
@@ -1,12 +1,12 @@
---
-image: /generated/articles-docs-lambda-approuterwebhooks.png
-id: approuterwebhooks
-title: appRouterWebhooks()
-slug: /lambda/approuterwebhooks
+image: /generated/articles-docs-lambda-approuterwebhook.png
+id: approuterwebhook
+title: appRouterWebhook()
+slug: /lambda/approuterwebhook
crumb: 'Lambda API'
---
-Simplifies the process of setting up Remotion Lambda Client in your Next.js app which is using App Router. Refer to [pagesRouterWebhooks()](/docs/lambda/pagerouterwebhooks) for doing the same in apps using Pages Router.
+Simplifies the process of setting up a [Lambda Webhook](/docs/lambda/webhooks) in your Next.js app which is using App Router. Refer to [`pagesRouterWebhook()`](/docs/lambda/pagesrouterwebhook) for doing the same in apps using Pages Router.
## API
@@ -26,15 +26,15 @@ Add your own custom headers to the outgoing response. Provide key-value pairs wh
### `onSuccess()`
-A function that is called with a `Payload` object as an argument when the incoming request indicates a successful event.
+A function that is called with a [`WebhookSuccessPayload`](/docs/lambda/webhooks#response) object as an argument when the incoming request indicates a successful event.
### `onError()`
-A function that is called with a `Payload` object as an argument when the incoming request indicates an error.
+A function that is called with a [`WebhookErrorPayload`](/docs/lambda/webhooks#response) object as an argument when the incoming request indicates an error.
### `onTimeout()`
-A function that is called with a `Payload` object as an argument when the incoming request indicates a timeout.
+A function that is called with a [`WebhookTimeoutPayload`](/docs/lambda/webhooks#response) object as an argument when the incoming request indicates a timeout.
## Example
@@ -62,4 +62,4 @@ See [Webhooks](/docs/lambda/webhooks) for an Express example.
## See also
- [Webhooks](/docs/lambda/webhooks)
-- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/lambda/src/simplifiers/index.ts)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/lambda/src/api/app-router-webhook.ts)
diff --git a/packages/docs/docs/lambda/pagerouterwebhooks.mdx b/packages/docs/docs/lambda/pagesrouterwebhooks.mdx
similarity index 59%
rename from packages/docs/docs/lambda/pagerouterwebhooks.mdx
rename to packages/docs/docs/lambda/pagesrouterwebhooks.mdx
index 292e76528d..70f0d0087c 100644
--- a/packages/docs/docs/lambda/pagerouterwebhooks.mdx
+++ b/packages/docs/docs/lambda/pagesrouterwebhooks.mdx
@@ -1,12 +1,12 @@
---
-image: /generated/articles-docs-lambda-pagerouterwebhooks.png
-id: pagerouterwebhooks
-title: pageRouterWebhooks()
-slug: /lambda/pagerouterwebhooks
+image: /generated/articles-docs-lambda-pagesrouterwebhooks.png
+id: pagesrouterwebhook
+title: pagesRouterWebhook()
+slug: /lambda/pagesrouterwebhook
crumb: 'Lambda API'
---
-Simplifies the process of setting up Remotion Lambda Client in your Next.js app which is using Pages Router. Similar to [appRouterWebhooks()](/docs/lambda/approuterwebhooks).
+Simplifies the process of setting up a [Lambda Webhook](/docs/lambda/webhooks) in your Next.js app which is using Pages Router. Similar to [`appRouterWebhook()`](/docs/lambda/approuterwebhook).
## API
@@ -26,15 +26,15 @@ Add your own custom headers to the outgoing response. Provide key-value pairs wh
### `onSuccess()`
-A function that is called with a `Payload` object as an argument when the incoming request indicates a successful event.
+A function that is called with a [`WebhookSuccessPayload`](/docs/lambda/webhooks#response) object as an argument when the incoming request indicates a successful event.
### `onError()`
-A function that is called with a `Payload` object as an argument when the incoming request indicates an error.
+A function that is called with a [`WebhookErrorPayload`](/docs/lambda/webhooks#response) object as an argument when the incoming request indicates an error.
### `onTimeout()`
-A function that is called with a `Payload` object as an argument when the incoming request indicates a timeout.
+A function that is called with a [`WebhookTimeoutPayload`](/docs/lambda/webhooks#response) object as an argument when the incoming request indicates a timeout.
## Example
@@ -61,4 +61,4 @@ See [Webhooks](/docs/lambda/webhooks) for an Express example.
## See also
- [Webhooks](/docs/lambda/webhooks)
-- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/lambda/src/simplifiers/index.ts)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/lambda/src/api/pages-router-webhook.ts)
diff --git a/packages/docs/docs/lambda/webhooks.mdx b/packages/docs/docs/lambda/webhooks.mdx
index 8c77725b11..ed0dc7de46 100644
--- a/packages/docs/docs/lambda/webhooks.mdx
+++ b/packages/docs/docs/lambda/webhooks.mdx
@@ -38,44 +38,39 @@ You can use these headers to verify the authenticity of the request, to check th
The request body has the following structure:
```ts
-type WebhookPayload =
- | {
- type: 'error';
- errors: {
- message: string;
- name: string;
- stack: string;
- }[];
- renderId: string;
- expectedBucketOwner: string;
- bucketName: string;
- customData: Record<string, unkown>;
- }
- | {
- type: 'success';
- lambdaErrors: EnhancedErrorInfo[];
- outputUrl: string | undefined;
- outputFile: string | undefined;
- timeToFinish: number | undefined;
- renderId: string;
- expectedBucketOwner: string;
- bucketName: string;
- customData: Record<string, unkown>;
- // Available from v3.3.11
- costs: {
- estimatedCost: number;
- estimatedDisplayCost: string;
- currency: string;
- disclaimer: string;
- };
- }
- | {
- type: 'timeout';
- renderId: string;
- expectedBucketOwner: string;
- bucketName: string;
- customData: Record<string, unkown>;
- };
+type StaticWebhookPayload = {
+ renderId: string;
+ expectedBucketOwner: string;
+ bucketName: string;
+ customData: Record<string, unknown> | null;
+};
+
+export type WebhookErrorPayload = StaticWebhookPayload & {
+ type: 'error';
+ errors: {
+ message: string;
+ name: string;
+ stack: string;
+ }[];
+};
+
+export type WebhookSuccessPayload = StaticWebhookPayload & {
+ type: 'success';
+ lambdaErrors: EnhancedErrorInfo[];
+ outputUrl: string | undefined;
+ outputFile: string | undefined;
+ timeToFinish: number | undefined;
+ costs: AfterRenderCost;
+};
+
+export type WebhookTimeoutPayload = StaticWebhookPayload & {
+ type: 'timeout';
+};
+
+export type WebhookPayload =
+ | WebhookErrorPayload
+ | WebhookSuccessPayload
+ | WebhookTimeoutPayload;
```
The fields [`renderId`](/docs/lambda/rendermediaonlambda#renderid), [`bucketName`](/docs/lambda/rendermediaonlambda#bucketname) will be returned [just like they are returned by `renderMediaOnLambda()` itself](/docs/lambda/rendermediaonlambda#return-value).
@@ -205,41 +200,46 @@ router.post("/my-remotion-webhook-endpoint", jsonParser, (req, res) => {
## Example webhook endpoint (Next.JS App Router)
-Similary, here is an example endpoint in Next.JS for the App Router using [appRouterWebhooks()](/docs/lambda/approuterwebhooks)
+Similarly, here is an example endpoint in Next.JS for the App Router using [`appRouterWebhook()`](/docs/lambda/approuterwebhook). Available from v4.0.246.
```tsx twoslash title="app/api/webhook.ts"
-import {
- appRouterWebhooks
-} from '@remotion/lambda/client';
-
-export const POST = appRouterWebhooks(
- {
- secret: 'mysecret',
- testing: true,
- onTimeout: ()=>(console.log("timeout"))
- }
-)
-
+const ENABLE_TESTING = false;
+
+// ---cut---
+import {appRouterWebhook} from '@remotion/lambda/client';
+
+export const POST = appRouterWebhook({
+ secret: 'mysecret',
+ // Enable testing through the tool below
+ testing: ENABLE_TESTING,
+ onSuccess: ({renderId}) => console.log('Finished render', renderId),
+ onTimeout: ({renderId}) => console.log('Time out', renderId),
+ onError: ({renderId}) => console.log('Error', renderId),
+});
+
export const OPTIONS = POST;
```
## Example webhook endpoint (Next.JS Pages Router)
-The same endpoint as above, but using the Pages Router with the help of [pageRouterWebhooks()](/docs/lambda/pagerouterwebhooks)
+The same endpoint as above, but using the Pages Router with the help of [`pagesRouterWebhook()`](/docs/lambda/pagesrouterwebhook). Available from v4.0.246.
```tsx twoslash title="pages/api/webhook.ts"
-import {
- pageRouterWebhooks
-} from '@remotion/lambda/client';
-
-const handler = pageRouterWebhooks(
- {
- secret: 'mysecret',
- testing: true,
- onError: () => (console.log('Something went wrong'))
- }
-)
-export default handler
+const ENABLE_TESTING = false;
+
+// ---cut---
+
+import {pagesRouterWebhook} from '@remotion/lambda/client';
+
+const handler = pagesRouterWebhook({
+ secret: 'mysecret',
+ // Enable testing through the tool below
+ testing: ENABLE_TESTING,
+ onSuccess: ({renderId}) => console.log('Finished render', renderId),
+ onTimeout: ({renderId}) => console.log('Time out', renderId),
+ onError: ({renderId}) => console.log('Error', renderId),
+});
+export default handler;
```
## Test your webhook endpoint
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 73b77483e5..24bd37310b 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -250,8 +250,8 @@ module.exports = {
'lambda/simulatepermissions',
'lambda/speculatefunctionname',
'lambda/validatewebhooksignature',
- 'lambda/approuterwebhooks',
- 'lambda/pagerouterwebhooks'
+ 'lambda/approuterwebhook',
+ 'lambda/pagesrouterwebhook',
],
},
{
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 2de7ecf05a..928e9d950b 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -3100,6 +3100,15 @@ export const articles = [
noAi: false,
slug: 'lambda/getuserpolicy',
},
+ {
+ id: 'pagesrouterwebhook',
+ title: 'pagesRouterWebhook()',
+ relativePath: 'docs/lambda/pagesrouterwebhooks.mdx',
+ compId: 'articles-docs-lambda-pagesrouterwebhooks',
+ crumb: 'Lambda API',
+ noAi: false,
+ slug: 'lambda/pagesrouterwebhook',
+ },
{
id: 'concurrency',
title: 'Concurrency',
@@ -3244,15 +3253,6 @@ export const articles = [
noAi: false,
slug: 'lambda/custom-destination',
},
- {
- id: 'approuterwebhooks',
- title: 'appRouterWebhooks()',
- relativePath: 'docs/lambda/approuterwebhooks.mdx',
- compId: 'articles-docs-lambda-approuterwebhooks',
- crumb: 'Lambda API',
- noAi: false,
- slug: 'lambda/approuterwebhooks',
- },
{
id: 'deletefunction',
title: 'deleteFunction()',
@@ -3532,6 +3532,15 @@ export const articles = [
noAi: false,
slug: 'lambda/without-iam/example',
},
+ {
+ id: 'approuterwebhook',
+ title: 'appRouterWebhook()',
+ relativePath: 'docs/lambda/approuterwebhook.mdx',
+ compId: 'articles-docs-lambda-approuterwebhook',
+ crumb: 'Lambda API',
+ noAi: false,
+ slug: 'lambda/approuterwebhook',
+ },
{
id: 'downloadvideo',
title: 'downloadVideo()',
@@ -3730,15 +3739,6 @@ export const articles = [
noAi: false,
slug: 'lambda/deploysite',
},
- {
- id: 'pagerouterwebhooks',
- title: 'pageRouterWebhooks()',
- relativePath: 'docs/lambda/pagerouterwebhooks.mdx',
- compId: 'articles-docs-lambda-pagerouterwebhooks',
- crumb: 'Lambda API',
- noAi: false,
- slug: 'lambda/pagerouterwebhooks',
- },
{
id: 'uninstall',
title: 'Uninstall Lambda',
diff --git a/packages/docs/static/generated/articles-docs-lambda-approuterwebhook.png b/packages/docs/static/generated/articles-docs-lambda-approuterwebhook.png
new file mode 100644
index 0000000000..f0747a3709
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-lambda-approuterwebhook.png differ
diff --git a/packages/docs/static/generated/articles-docs-lambda-approuterwebhooks.png b/packages/docs/static/generated/articles-docs-lambda-approuterwebhooks.png
deleted file mode 100644
index 6a7c59d8d3..0000000000
Binary files a/packages/docs/static/generated/articles-docs-lambda-approuterwebhooks.png and /dev/null differ
diff --git a/packages/docs/static/generated/articles-docs-lambda-pagerouterwebhooks.png b/packages/docs/static/generated/articles-docs-lambda-pagerouterwebhooks.png
deleted file mode 100644
index 3c1fba154c..0000000000
Binary files a/packages/docs/static/generated/articles-docs-lambda-pagerouterwebhooks.png and /dev/null differ
diff --git a/packages/docs/static/generated/articles-docs-lambda-pagesrouterwebhooks.png b/packages/docs/static/generated/articles-docs-lambda-pagesrouterwebhooks.png
new file mode 100644
index 0000000000..fbe3488a81
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-lambda-pagesrouterwebhooks.png differ
diff --git a/packages/lambda/src/api/app-router-webhook.ts b/packages/lambda/src/api/app-router-webhook.ts
new file mode 100644
index 0000000000..9ffbee9ae2
--- /dev/null
+++ b/packages/lambda/src/api/app-router-webhook.ts
@@ -0,0 +1,64 @@
+import type {
+ WebhookErrorPayload,
+ WebhookPayload,
+ WebhookSuccessPayload,
+ WebhookTimeoutPayload,
+} from '@remotion/serverless';
+import {validateWebhookSignature} from './validate-webhook-signature';
+
+export type NextWebhookArgs = {
+ testing?: boolean;
+ extraHeaders?: Record<string, string>;
+ secret: string;
+ onSuccess?: (payload: WebhookSuccessPayload) => void;
+ onTimeout?: (payload: WebhookTimeoutPayload) => void;
+ onError?: (payload: WebhookErrorPayload) => void;
+};
+
+export const appRouterWebhook = (
+ options: NextWebhookArgs,
+): ((req: Request) => Promise<Response>) => {
+ const {testing, extraHeaders, secret, onSuccess, onTimeout, onError} =
+ options;
+ return async function (req: Request): Promise<Response> {
+ let headers = extraHeaders || {};
+
+ if (testing) {
+ const testingheaders = {
+ 'Access-Control-Allow-Origin': 'https://www.remotion.dev',
+ 'Access-Control-Allow-Headers':
+ 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Remotion-Status, X-Remotion-Signature, X-Remotion-Mode',
+ 'Access-Control-Allow-Methods': 'OPTIONS,POST',
+ };
+ headers = {...headers, ...testingheaders};
+ }
+
+ if (req.method === 'OPTIONS') {
+ // do we have any use of the OPTIONS method other than the tester on webhooks page ? if so we can add a condition here to only return this if testing mode enabled
+ return new Response(null, {
+ headers,
+ });
+ }
+
+ // Parse the body properly
+ const body = await req.json();
+
+ validateWebhookSignature({
+ secret,
+ body,
+ signatureHeader: req.headers.get('X-Remotion-Signature') as string,
+ });
+
+ const payload = body as WebhookPayload;
+
+ if (payload.type === 'success' && onSuccess) {
+ onSuccess(payload);
+ } else if (payload.type === 'timeout' && onTimeout) {
+ onTimeout(payload);
+ } else if (payload.type === 'error' && onError) {
+ onError(payload);
+ }
+
+ return new Response(JSON.stringify({success: true}), {headers});
+ };
+};
diff --git a/packages/lambda/src/api/pages-router-webhook.ts b/packages/lambda/src/api/pages-router-webhook.ts
new file mode 100644
index 0000000000..8eeceaa9f5
--- /dev/null
+++ b/packages/lambda/src/api/pages-router-webhook.ts
@@ -0,0 +1,54 @@
+import type {WebhookPayload} from '@remotion/serverless';
+import type {NextApiRequest, NextApiResponse} from 'next';
+import type {NextWebhookArgs} from './app-router-webhook';
+import {validateWebhookSignature} from './validate-webhook-signature';
+
+const addHeaders = (res: NextApiResponse, headers: Record<string, string>) => {
+ Object.entries(headers).forEach(([key, value]) => {
+ res.setHeader(key, value);
+ });
+};
+
+export const pagesRouterWebhook = (options: NextWebhookArgs) => {
+ const {testing, extraHeaders, secret, onSuccess, onTimeout, onError} =
+ options;
+ return function (req: NextApiRequest, res: NextApiResponse): void {
+ addHeaders(res, extraHeaders || {});
+
+ if (testing) {
+ const testingheaders = {
+ 'Access-Control-Allow-Origin': 'https://www.remotion.dev',
+ 'Access-Control-Allow-Headers':
+ 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Remotion-Status, X-Remotion-Signature, X-Remotion-Mode',
+ 'Access-Control-Allow-Methods': 'OPTIONS,POST',
+ };
+
+ addHeaders(res, testingheaders);
+ }
+
+ if (req.method === 'OPTIONS') {
+ res.status(200).end();
+ return;
+ }
+
+ validateWebhookSignature({
+ secret,
+ body: req.body,
+ signatureHeader: req.headers['x-remotion-signature'] as string,
+ });
+
+ // If code reaches this path, the webhook is authentic.
+ const payload = req.body as WebhookPayload;
+ if (payload.type === 'success' && onSuccess) {
+ onSuccess(payload);
+ } else if (payload.type === 'timeout' && onTimeout) {
+ onTimeout(payload);
+ } else if (payload.type === 'error' && onError) {
+ onError(payload);
+ }
+
+ res.status(200).json({
+ success: true,
+ });
+ };
+};
diff --git a/packages/lambda/src/client.ts b/packages/lambda/src/client.ts
index b5ffdbefa2..3ca527432c 100644
--- a/packages/lambda/src/client.ts
+++ b/packages/lambda/src/client.ts
@@ -1,62 +1,47 @@
-import type {DeleteRenderInput} from './api/delete-render';
-import {deleteRender} from './api/delete-render';
-import {getCompositionsOnLambda} from './api/get-compositions-on-lambda';
-import {getFunctions} from './api/get-functions';
-import type {GetRenderProgressInput} from './api/get-render-progress';
-import {getRenderProgress} from './api/get-render-progress';
-import {getSites} from './api/get-sites';
-import type {PresignUrlInput} from './api/presign-url';
-import {presignUrl} from './api/presign-url';
-import type {
- RenderMediaOnLambdaInput,
- RenderMediaOnLambdaOutput,
-} from './api/render-media-on-lambda';
-import {
- renderMediaOnLambda,
- renderVideoOnLambda,
-} from './api/render-media-on-lambda';
-import type {
- RenderStillOnLambdaInput,
- RenderStillOnLambdaOutput,
-} from './api/render-still-on-lambda';
-import {renderStillOnLambda} from './api/render-still-on-lambda';
-import type {SpeculateFunctionNameInput} from './api/speculate-function-name';
-import {speculateFunctionName} from './api/speculate-function-name';
-import {validateWebhookSignature} from './api/validate-webhook-signature';
-import type {RenderProgress} from './shared/constants';
-import {appRouterWebhooks, pageRouterWebhooks} from './webhook-presets';
-export type {WebhookPayload} from '@remotion/serverless';
-
+export type {
+ WebhookErrorPayload,
+ WebhookPayload,
+ WebhookSuccessPayload,
+ WebhookTimeoutPayload,
+} from '@remotion/serverless';
export type {CustomCredentials, DeleteAfter} from '@remotion/serverless/client';
+export {NextWebhookArgs, appRouterWebhook} from './api/app-router-webhook';
+export {deleteRender, type DeleteRenderInput} from './api/delete-render';
export {
getAwsClient,
type GetAwsClientInput,
type GetAwsClientOutput,
} from './api/get-aws-client';
-export type {AwsRegion} from './regions';
export {
- appRouterWebhooks,
- deleteRender,
getCompositionsOnLambda,
- getFunctions,
- getRenderProgress,
+ type GetCompositionsOnLambdaInput,
+ type GetCompositionsOnLambdaOutput,
+} from './api/get-compositions-on-lambda';
+export {getFunctions, type GetFunctionsInput} from './api/get-functions';
+export {getRenderProgress} from './api/get-render-progress';
+export type {GetRenderProgressInput} from './api/get-render-progress';
+export {
getSites,
- pageRouterWebhooks,
- presignUrl,
+ type GetSitesInput,
+ type GetSitesOutput,
+} from './api/get-sites';
+export {pagesRouterWebhook} from './api/pages-router-webhook';
+export {presignUrl, type PresignUrlInput} from './api/presign-url';
+export {
renderMediaOnLambda,
- renderStillOnLambda,
renderVideoOnLambda,
+ type RenderMediaOnLambdaInput,
+ type RenderMediaOnLambdaOutput,
+} from './api/render-media-on-lambda';
+export {
+ renderStillOnLambda,
+ type RenderStillOnLambdaInput,
+ type RenderStillOnLambdaOutput,
+} from './api/render-still-on-lambda';
+export {
speculateFunctionName,
- validateWebhookSignature,
-};
-export type {
- DeleteRenderInput,
- GetRenderProgressInput,
- PresignUrlInput,
- RenderMediaOnLambdaInput,
- RenderMediaOnLambdaOutput,
- RenderProgress,
- RenderStillOnLambdaInput,
- RenderStillOnLambdaOutput,
- SpeculateFunctionNameInput,
-};
+ type SpeculateFunctionNameInput,
+} from './api/speculate-function-name';
+export {validateWebhookSignature} from './api/validate-webhook-signature';
+export type {AwsRegion} from './regions';
+export type {RenderProgress} from './shared/constants';
diff --git a/packages/lambda/src/webhook-presets/index.ts b/packages/lambda/src/webhook-presets/index.ts
deleted file mode 100644
index 41ff7490ba..0000000000
--- a/packages/lambda/src/webhook-presets/index.ts
+++ /dev/null
@@ -1,119 +0,0 @@
-import type {NextApiRequest, NextApiResponse} from 'next';
-import type {WebhookPayload} from '../client';
-import {validateWebhookSignature} from '../client';
-
-type AppRouterWebhookArgs = {
- testing?: boolean;
- extraHeaders?: Record<string, string>;
- secret: string;
- onSuccess?: (payload: WebhookPayload) => void;
- onTimeout?: (payload: WebhookPayload) => void;
- onError?: (payload: WebhookPayload) => void;
-};
-
-const appRouterWebhooks = (
- options: AppRouterWebhookArgs,
-): ((req: Request) => Promise<Response>) => {
- const {testing, extraHeaders, secret, onSuccess, onTimeout, onError} =
- options;
- return async function (req: Request): Promise<Response> {
- let headers = extraHeaders || {};
-
- if (testing) {
- const testingheaders = {
- 'Access-Control-Allow-Origin': 'https://www.remotion.dev',
- 'Access-Control-Allow-Headers':
- 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Remotion-Status, X-Remotion-Signature, X-Remotion-Mode',
- 'Access-Control-Allow-Methods': 'OPTIONS,POST',
- };
- headers = {...headers, ...testingheaders};
- }
-
- if (req.method === 'OPTIONS') {
- // do we have any use of the OPTIONS method other than the tester on webhooks page ? if so we can add a condition here to only return this if testing mode enabled
- return new Response(null, {
- headers,
- });
- }
-
- // Parse the body properly
- const body = await req.json();
-
- validateWebhookSignature({
- secret,
- body,
- signatureHeader: req.headers.get('X-Remotion-Signature') as string,
- });
-
- const payload = body as WebhookPayload;
-
- if (payload.type === 'success' && onSuccess) {
- onSuccess(payload);
- } else if (payload.type === 'timeout' && onTimeout) {
- onTimeout(payload);
- } else if (payload.type === 'error' && onError) {
- onError(payload);
- }
-
- return new Response(JSON.stringify({success: true}), {headers});
- };
-};
-
-const headersMutator = (
- res: NextApiResponse,
- headers: Record<string, string>,
-) => {
- Object.entries(headers).forEach(([key, value]) => {
- res.setHeader(key, value);
- });
-};
-
-const pageRouterWebhooks = (options: AppRouterWebhookArgs) => {
- const {testing, extraHeaders, secret, onSuccess, onTimeout, onError} =
- options;
- return async function (
- req: NextApiRequest,
- res: NextApiResponse,
- ): Promise<void> {
- // set the headers
- headersMutator(res, extraHeaders || {});
-
- if (testing) {
- const testingheaders = {
- 'Access-Control-Allow-Origin': 'https://www.remotion.dev',
- 'Access-Control-Allow-Headers':
- 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Remotion-Status, X-Remotion-Signature, X-Remotion-Mode',
- 'Access-Control-Allow-Methods': 'OPTIONS,POST',
- };
- // add the headers for testing
- headersMutator(res, testingheaders);
- }
-
- if (req.method === 'OPTIONS') {
- res.status(200).end();
- return;
- }
-
- validateWebhookSignature({
- secret,
- body: req.body,
- signatureHeader: req.headers['x-remotion-signature'] as string,
- });
-
- // If code reaches this path, the webhook is authentic.
- const payload = req.body as WebhookPayload;
- if (payload.type === 'success' && onSuccess) {
- onSuccess(payload);
- } else if (payload.type === 'timeout' && onTimeout) {
- onTimeout(payload);
- } else if (payload.type === 'error' && onError) {
- onError(payload);
- }
-
- res.status(200).json({
- success: true,
- });
- };
-};
-
-export {appRouterWebhooks, pageRouterWebhooks};
diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.ts
index 2b3e8107e1..99dc8a72fa 100644
--- a/packages/serverless/src/index.ts
+++ b/packages/serverless/src/index.ts
@@ -15,7 +15,14 @@ export {stillHandler} from './handlers/still';
export {infoHandler} from './info';
export {innerHandler} from './inner-routine';
export {inspectErrors} from './inspect-error';
-export {WebhookClient, WebhookPayload, invokeWebhook} from './invoke-webhook';
+export {
+ WebhookClient,
+ WebhookErrorPayload,
+ WebhookPayload,
+ WebhookSuccessPayload,
+ WebhookTimeoutPayload,
+ invokeWebhook,
+} from './invoke-webhook';
export {setCurrentRequestId, stopLeakDetection} from './leak-detection';
export {
OVERHEAD_TIME_PER_LAMBDA,
diff --git a/packages/serverless/src/invoke-webhook.ts b/packages/serverless/src/invoke-webhook.ts
index 9fd032320f..a945fe3bec 100644
--- a/packages/serverless/src/invoke-webhook.ts
+++ b/packages/serverless/src/invoke-webhook.ts
@@ -16,33 +16,39 @@ export function calculateSignature(payload: string, secret: string | null) {
return signature;
}
-type DynamicWebhookPayload =
- | {
- type: 'error';
- errors: {
- message: string;
- name: string;
- stack: string;
- }[];
- }
- | {
- type: 'success';
- lambdaErrors: EnhancedErrorInfo[];
- outputUrl: string | undefined;
- outputFile: string | undefined;
- timeToFinish: number | undefined;
- costs: AfterRenderCost;
- }
- | {
- type: 'timeout';
- };
-
-export type WebhookPayload = {
+type StaticWebhookPayload = {
renderId: string;
expectedBucketOwner: string;
bucketName: string;
customData: Record<string, unknown> | null;
-} & DynamicWebhookPayload;
+};
+
+export type WebhookErrorPayload = StaticWebhookPayload & {
+ type: 'error';
+ errors: {
+ message: string;
+ name: string;
+ stack: string;
+ }[];
+};
+
+export type WebhookSuccessPayload = StaticWebhookPayload & {
+ type: 'success';
+ lambdaErrors: EnhancedErrorInfo[];
+ outputUrl: string | undefined;
+ outputFile: string | undefined;
+ timeToFinish: number | undefined;
+ costs: AfterRenderCost;
+};
+
+export type WebhookTimeoutPayload = StaticWebhookPayload & {
+ type: 'timeout';
+};
+
+export type WebhookPayload =
+ | WebhookErrorPayload
+ | WebhookSuccessPayload
+ | WebhookTimeoutPayload;
// Don't handle 304 status code (Not Modified) as a redirect,
// since the browser will display the right page.