Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/content/docs/rules/snippets/create-dashboard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ import { Render } from "~/components";

1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/), and select your account and website.

2. Go to **Rules** > **Snippets**, and select **Create a Snippet**.
2. Go to **Rules** > **Snippets**.

3. In **Snippet name**, enter a descriptive name for the snippet. You cannot change the name after creating the snippet.
3. (Optional) If you have not created any snippets yet, select one of the snippet templates that address common use cases. Then, review and adjust the proposed snippet code.

4. Enter the snippet's JavaScript code in the code editor. You can test how your snippet will handle incoming requests using the **HTTP** and **Preview** tabs.
To start from scratch, select **Create Snippet**.

5. Select **Snippet rule** to configure when the snippet will run.
4. In **Snippet name**, enter a descriptive name for the snippet. You cannot change the name after creating the snippet.

6. Under **Run this Snippet if incoming requests match**, select if you wish to run the snippet only for requests that match a custom filter expression or for all incoming requests.
5. Enter the snippet's JavaScript code in the code editor. You can test how your snippet will handle incoming requests using the **HTTP** and **Preview** tabs.

7. (Optional) To define a custom expression, use the Expression Builder (specifying one or more values for **Field**, **Operator**, and **Value**) or manually enter an expression using the Expression Editor. For more information, refer to [Edit expressions in the dashboard](/ruleset-engine/rules-language/expressions/edit-expressions/).
6. Select **Snippet rule** to configure when the snippet will run.

8. Select **Done**.
7. Under **Run this Snippet if incoming requests match**, select if you wish to run the snippet only for requests that match a custom filter expression or for all incoming requests.

9. To deploy your snippet, select **Deploy**. If you are not ready to deploy your snippet, open the dropdown next to **Deploy** and select **Save as Draft**.
8. (Optional) To define a custom expression, use the Expression Builder (specifying one or more values for **Field**, **Operator**, and **Value**) or manually enter an expression using the Expression Editor. For more information, refer to [Edit expressions in the dashboard](/ruleset-engine/rules-language/expressions/edit-expressions/).

<Render file="rules-creation-dash-dns-popup" />
9. Select **Done**.

10. To deploy your snippet, select **Deploy**. If you are not ready to deploy your snippet, open the dropdown next to **Deploy** and select **Save as Draft**.

<Render file="rules-creation-dash-dns-popup" />
12 changes: 7 additions & 5 deletions src/content/docs/rules/snippets/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ For code samples addressing common use cases, please refer to the [Examples](/ru

## Snippets elements

To create and deploy a Snippet, you need to define the following elements:
To create and deploy a snippet, you need to define the following elements:

- **Code snippet**: JavaScript code to be executed during the request-handling process.
- **Snippet rule**: A [filter expression](/ruleset-engine/rules-language/expressions/) that determines which requests the Snippet will be applied to. Each Snippet can only be associated with one Snippet Rule.
- **Snippet rule**: A [filter expression](/ruleset-engine/rules-language/expressions/) that determines which requests the Snippet will be applied to. Each snippet can only be associated with one snippet rule.

For more information, refer to the [How it works](/rules/snippets/how-it-works/) and [Create a snippet in the dashboard](/rules/snippets/create-dashboard/) sections.
For more information, refer to [How it works](/rules/snippets/how-it-works/) and [Create a snippet in the dashboard](/rules/snippets/create-dashboard/).

:::note
If you have used the Cloudflare API to create a code snippet that is not associated with a snippet rule, the Cloudflare dashboard will show that code snippet in a separate tab called **Unused Snippets**. You can either edit the snippet code and associate it with a snippet rule, or delete the unused code snippet.
:::

## Templates

Expand All @@ -41,9 +45,7 @@ For more information, refer to the [How it works](/rules/snippets/how-it-works/)

<FeatureTable id="rules.snippets" />

:::caution[Redirects will count as subrequests]
Each <GlossaryTooltip term="Snippets subrequest" prepend="A subrequest is ">subrequest</GlossaryTooltip> in a redirect chain counts against the subrequest limit. This means that if a subrequest was redirected it would count as two subrequests. To avoid issues, ensure that you make a subrequest to the end location of the redirect chain.
:::

## Limits

Expand Down
Loading