Skip to content

Commit f884dd6

Browse files
[Rules] Chore: Move goals and operations to tags (#25385)
* [Rules] Chore: Move goals and operations to tags * Update filters in index pages * remove schema values --------- Co-authored-by: kodster28 <[email protected]>
1 parent dcebdd8 commit f884dd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+207
-271
lines changed

src/content/docs/rules/examples.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
pcx_content_type: navigation
43
title: Examples
54
sidebar:
@@ -19,5 +18,5 @@ We have a separate listing for [Cache rules examples](/cache/how-to/cache-rules/
1918
<ResourcesBySelector
2019
directory="rules"
2120
types={["example"]}
22-
filterables={["products", "goal", "operation"]}
21+
filterables={["products", "tags"]}
2322
/>

src/content/docs/rules/snippets/examples/ab-testing-same-url.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
---
2-
32
summary: Set up an A/B test by controlling what response is served based on cookies.
4-
goal:
3+
tags:
54
- A/B testing
6-
operation:
7-
- Cookies manipulation
8-
- Rewrite URL
5+
- Cookies
6+
- URL rewrite
97
products:
108
- Snippets
119
pcx_content_type: example

src/content/docs/rules/snippets/examples/append-dates-to-cookies.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
32
summary: Dynamically set a cookie expiration and test group.
4-
goal:
3+
tags:
54
- A/B testing
6-
operation:
7-
- Cookies manipulation
5+
- Cookies
86
products:
97
- Snippets
108
pcx_content_type: example

src/content/docs/rules/snippets/examples/auth-with-headers.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
---
2-
32
summary: Allow or deny a request based on a known pre-shared key in a header.
43
This is not meant to replace the [WebCrypto
54
API](/workers/runtime-apis/web-crypto/).
6-
goal:
5+
tags:
76
- Authentication
8-
operation:
97
- Request modification
108
products:
119
- Snippets

src/content/docs/rules/snippets/examples/bot-data-to-origin.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
---
2-
32
summary: Send [Bots](/bots/) information to your origin. Refer to [Bot
43
Managenent variables](/bots/reference/bot-management-variables/) for a full
54
list of available fields.
6-
goal:
7-
- Manage headers
8-
operation:
5+
tags:
6+
- Headers
97
- Request modification
108
products:
119
- Snippets

src/content/docs/rules/snippets/examples/bots-to-honeypot.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
---
2-
32
summary: Use the [bot score
43
field](/workers/runtime-apis/request/#incomingrequestcfproperties) to send
54
bots to a honeypot.
6-
goal:
7-
- Routing
8-
operation:
9-
- Redirect
5+
tags:
6+
- Redirects
107
products:
118
- Snippets
129
pcx_content_type: example

src/content/docs/rules/snippets/examples/bulk-redirect-map.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
---
2-
32
summary: Redirect requests to certain URLs based on a mapped object to the
43
request's URL.
5-
goal:
6-
- Routing
7-
operation:
8-
- Redirect
4+
tags:
5+
- Redirects
96
products:
107
- Snippets
118
pcx_content_type: example

src/content/docs/rules/snippets/examples/country-code-redirect.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
32
summary: Redirect a response based on the country code in the header of a visitor.
4-
goal:
3+
tags:
54
- Localization
6-
operation:
7-
- Redirect
5+
- Redirects
86
products:
97
- Snippets
108
preview:
Lines changed: 75 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
---
2-
32
summary: Control cache programmatically. Use this template to optimize performance and implement custom caching strategies.
4-
goal:
5-
- Other
6-
operation:
7-
- Cache
3+
tags:
4+
- Caching
85
products:
96
- Snippets
107
pcx_content_type: example
@@ -22,49 +19,54 @@ const USE_QUERY_STRING = true; // Include query string in the cache key
2219
const INCLUDE_HEADERS = ["User-Agent"]; // Headers to include in the cache key
2320

2421
export default {
25-
async fetch(request, env, ctx) {
26-
// Generate a custom cache key based on user preferences
27-
const cacheKey = createCacheKey(request);
28-
console.log(`Retrieving cache for: ${cacheKey.url}.`)
29-
30-
// Access the default Cache API
31-
const cache = caches.default;
32-
33-
// Attempt to retrieve the cached response
34-
let response = await cache.match(cacheKey);
35-
36-
if (!response) {
37-
// Cache miss: Fetch the asset from the origin
38-
console.log(`Cache miss for: ${cacheKey.url}. Fetching from origin...`);
39-
response = await fetch(request);
40-
41-
// Wrap the origin response for caching
42-
response = new Response(response.body, response);
43-
44-
// Set Cache-Control headers to define the TTL
45-
response.headers.set("Cache-Control", `s-maxage=${CACHE_DURATION_SECONDS}`);
46-
response.headers.set("x-snippets-cache", "stored");
47-
48-
// Store the response in the cache
49-
await cache.put(cacheKey, response.clone());
50-
} else {
51-
// Cache hit: Return the cached response
52-
console.log(`Cache hit for: ${cacheKey.url}.`);
53-
response = new Response(response.body, response);
54-
response.headers.set("x-snippets-cache", "hit");
55-
56-
// Optionally check if the cache should expire based on age
57-
const ageHeader = response.headers.get("Age");
58-
if (ageHeader && parseInt(ageHeader, 10) > CACHE_DURATION_SECONDS) {
59-
console.log(`Cache expired for: ${cacheKey.url}. Deleting cached response...`);
60-
await cache.delete(cacheKey);
61-
response.headers.set("x-snippets-cache", "deleted");
62-
}
63-
}
64-
65-
// Return the response to the client
66-
return response;
67-
},
22+
async fetch(request, env, ctx) {
23+
// Generate a custom cache key based on user preferences
24+
const cacheKey = createCacheKey(request);
25+
console.log(`Retrieving cache for: ${cacheKey.url}.`);
26+
27+
// Access the default Cache API
28+
const cache = caches.default;
29+
30+
// Attempt to retrieve the cached response
31+
let response = await cache.match(cacheKey);
32+
33+
if (!response) {
34+
// Cache miss: Fetch the asset from the origin
35+
console.log(`Cache miss for: ${cacheKey.url}. Fetching from origin...`);
36+
response = await fetch(request);
37+
38+
// Wrap the origin response for caching
39+
response = new Response(response.body, response);
40+
41+
// Set Cache-Control headers to define the TTL
42+
response.headers.set(
43+
"Cache-Control",
44+
`s-maxage=${CACHE_DURATION_SECONDS}`,
45+
);
46+
response.headers.set("x-snippets-cache", "stored");
47+
48+
// Store the response in the cache
49+
await cache.put(cacheKey, response.clone());
50+
} else {
51+
// Cache hit: Return the cached response
52+
console.log(`Cache hit for: ${cacheKey.url}.`);
53+
response = new Response(response.body, response);
54+
response.headers.set("x-snippets-cache", "hit");
55+
56+
// Optionally check if the cache should expire based on age
57+
const ageHeader = response.headers.get("Age");
58+
if (ageHeader && parseInt(ageHeader, 10) > CACHE_DURATION_SECONDS) {
59+
console.log(
60+
`Cache expired for: ${cacheKey.url}. Deleting cached response...`,
61+
);
62+
await cache.delete(cacheKey);
63+
response.headers.set("x-snippets-cache", "deleted");
64+
}
65+
}
66+
67+
// Return the response to the client
68+
return response;
69+
},
6870
};
6971

7072
/**
@@ -73,28 +75,30 @@ export default {
7375
* @returns {Request} - A valid cache key based on the URL
7476
*/
7577
function createCacheKey(request) {
76-
const url = new URL(request.url); // Use the request's base URL
77-
const cacheKey = new URL(url.origin); // Start with the origin (scheme + hostname)
78-
79-
// Optionally include the path
80-
if (USE_PATH) {
81-
cacheKey.pathname = url.pathname;
82-
}
83-
84-
// Optionally include the query string
85-
if (USE_QUERY_STRING) {
86-
cacheKey.search = url.search;
87-
}
88-
89-
// Optionally include specific headers
90-
if (INCLUDE_HEADERS.length > 0) {
91-
const headerParts = INCLUDE_HEADERS.map(header => `${header}=${request.headers.get(header) || ""}`).join("&");
92-
cacheKey.searchParams.append("headers", headerParts);
93-
}
94-
95-
// Return the constructed URL as the cache key
96-
return new Request(cacheKey.toString(), {
97-
method: "GET"
98-
});
78+
const url = new URL(request.url); // Use the request's base URL
79+
const cacheKey = new URL(url.origin); // Start with the origin (scheme + hostname)
80+
81+
// Optionally include the path
82+
if (USE_PATH) {
83+
cacheKey.pathname = url.pathname;
84+
}
85+
86+
// Optionally include the query string
87+
if (USE_QUERY_STRING) {
88+
cacheKey.search = url.search;
89+
}
90+
91+
// Optionally include specific headers
92+
if (INCLUDE_HEADERS.length > 0) {
93+
const headerParts = INCLUDE_HEADERS.map(
94+
(header) => `${header}=${request.headers.get(header) || ""}`,
95+
).join("&");
96+
cacheKey.searchParams.append("headers", headerParts);
97+
}
98+
99+
// Return the constructed URL as the cache key
100+
return new Request(cacheKey.toString(), {
101+
method: "GET",
102+
});
99103
}
100104
```

src/content/docs/rules/snippets/examples/debugging-logs.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
---
2-
32
summary: Send debugging information in an errored response to a logging service.
4-
goal:
3+
tags:
54
- Logging
6-
operation:
75
- Response modification
86
products:
97
- Snippets

0 commit comments

Comments
 (0)