You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/rules/snippets/create-dashboard.mdx
+13-9Lines changed: 13 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,20 +13,24 @@ import { Render } from "~/components";
13
13
14
14
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/), and select your account and website.
15
15
16
-
2. Go to **Rules** > **Snippets**, and select **Create a Snippet**.
16
+
2. Go to **Rules** > **Snippets**.
17
17
18
-
3.In **Snippet name**, enter a descriptive name for the snippet. You cannot change the name after creating the snippet.
18
+
3.(Optional) If you have not created any snippets yet, select one of the snippet templates that addresses a common use case. Then, review and adjust the proposed snippet code.
19
19
20
-
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.
20
+
To start from scratch, select **Create Snippet**.
21
21
22
-
5. Select**Snippet rule** to configure when the snippet will run.
22
+
4. In**Snippet name**, enter a descriptive name for the snippet. You cannot change the name after creating the snippet.
23
23
24
-
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.
24
+
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.
25
25
26
-
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/).
26
+
6. Select **Snippet rule** to configure when the snippet will run.
27
27
28
-
8. Select**Done**.
28
+
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.
29
29
30
-
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**.
30
+
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/).
31
31
32
-
<Renderfile="rules-creation-dash-dns-popup" />
32
+
9. Select **Done**.
33
+
34
+
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**.
Copy file name to clipboardExpand all lines: src/content/docs/rules/snippets/index.mdx
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,12 +24,16 @@ For code samples addressing common use cases, please refer to the [Examples](/ru
24
24
25
25
## Snippets elements
26
26
27
-
To create and deploy a Snippet, you need to define the following elements:
27
+
To create and deploy a snippet, you need to define the following elements:
28
28
29
29
-**Code snippet**: JavaScript code to be executed during the request-handling process.
30
-
-**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.
30
+
-**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.
31
31
32
-
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.
32
+
For more information, refer to [How it works](/rules/snippets/how-it-works/) and [Create a snippet in the dashboard](/rules/snippets/create-dashboard/).
33
+
34
+
:::note
35
+
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.
36
+
:::
33
37
34
38
## Templates
35
39
@@ -41,9 +45,7 @@ For more information, refer to the [How it works](/rules/snippets/how-it-works/)
41
45
42
46
<FeatureTableid="rules.snippets" />
43
47
44
-
:::caution[Redirects will count as subrequests]
45
48
Each <GlossaryTooltipterm="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.
0 commit comments