Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/103-early-hints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sidebar:
description: Allow a client to request static assets while waiting for the HTML response.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/103-early-hints)

import { TabItem, Tabs } from "~/components";

`103` Early Hints is an HTTP status code designed to speed up content delivery. When enabled, Cloudflare can cache the `Link` headers marked with preload and/or preconnect from HTML pages and serve them in a `103` Early Hints response before reaching the origin server. Browsers can use these hints to fetch linked assets while waiting for the origin’s final response, dramatically improving page load speeds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description: Access custom Cloudflare properties and control how Cloudflare
features are applied to every request.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/accessing-the-cloudflare-object)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/aggregate-requests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ description: Send two GET request to two urls and aggregates the responses into
one response.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/aggregate-requests)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/alter-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ description: Example of how to add, change, or delete headers sent in a request
or returned in a response.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/alter-headers)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/cache-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sidebar:
description: Use the Cache API to store responses in Cloudflare's cache.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/cache-api)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/cache-post-request.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sidebar:
description: Cache POST requests using the Cache API.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/cache-post-request)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/cache-tags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ sidebar:
description: Send Additional Cache Tags using Workers
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/cache-tags)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/cache-using-fetch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ description: Determine how to cache a resource by setting TTLs, custom cache
keys, and cache headers in a fetch request.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/cache-using-fetch)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/conditional-response.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description: Return a response based on the incoming request's URL, HTTP method,
User Agent, IP address, ASN or device type.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/conditional-response)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/cors-header-proxy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ sidebar:
description: Add the necessary CORS headers to a third party API response.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/cors-header-proxy)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/country-code-redirect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ sidebar:
description: Redirect a response based on the country code in the header of a visitor.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/country-code-redirect)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/cron-trigger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ sidebar:
description: Set a Cron Trigger for your Worker.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/cron-trigger)

import { Render, TabItem, Tabs, WranglerConfig } from "~/components";

<Render file="cron-trigger-example" />
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/data-loss-prevention.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description: Protect sensitive data to prevent data loss, and send alerts to a
webhooks server in the event of a data breach.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/data-loss-prevention)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/debugging-logs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ sidebar:
description: Send debugging information in an errored response to a logging service.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/debugging-logs)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/extract-cookie-value.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description: Given the cookie name, get the value of a cookie. You can also use
cookies for A/B testing.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/extract-cookie-value)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/fetch-html.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ description: Send a request to a remote server, read HTML from the response, and
serve that HTML.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/fetch-html)

import { Render, TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/fetch-json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description: Send a GET request and read in JSON from the response. Use to fetch
external data.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/fetch-json)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ sidebar:
description: Fetch weather data from an API using the user's geolocation data.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/geolocation-app-weather)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ sidebar:
description: Personalize website styling based on localized user time.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/geolocation-custom-styling)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ sidebar:
description: Get all geolocation data fields and display them in HTML.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/geolocation-hello-world)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/hot-link-protection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ description: Block other websites from linking to your content. This is useful
for protecting images.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/hot-link-protection)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/images-workers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ description: Set up custom domain for Images using a Worker or serve images
using a prefix path and Cloudflare registered domain.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/images-workers)

import { TabItem, Tabs } from "~/components";

To serve images from a custom domain:
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/logging-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ sidebar:
description: Examine the contents of a Headers object by logging to console with a Map.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/logging-headers)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ description: Create a modified request with edited properties based off of an
incoming request.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/modify-request-property)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/modify-response.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ description: Fetch and modify response properties which are immutable by
creating a copy first.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/modify-response)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ sidebar:
description: Set multiple Cron Triggers on three different schedules.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/multiple-cron-triggers)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/openai-sdk-streaming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ head: []
description: Use the OpenAI v4 SDK to stream responses from OpenAI.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/openai-sdk-streaming)

import { TabItem, Tabs } from "~/components";

In order to run this code, you must install the OpenAI SDK by running `npm i openai`.
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/post-json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ sidebar:
description: Send a POST request with JSON data. Use to share data with external servers.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/post-json)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description: Protect against timing attacks by safely comparing values using
`timingSafeEqual`.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/protect-against-timing-attacks)

import { TabItem, Tabs } from "~/components";

The [`crypto.subtle.timingSafeEqual`](/workers/runtime-apis/web-crypto/#timingsafeequal) function compares two values using a constant-time algorithm. The time taken is independent of the contents of the values.
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/read-post.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ description: Serve an HTML form, then read POST requests. Use also to read JSON
or POST data from an incoming request.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/read-post)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/redirect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ description: Redirect requests from one URL to another or from one set of URLs
to another set.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/redirect)

import { Render, TabItem, Tabs } from "~/components";

## Redirect all requests to one URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ description: Respond to the Worker request with the response from another
website (example.com in this example).
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/respond-with-another-site)

import { Render, TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/return-html.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ sidebar:
description: Deliver an HTML page from an HTML string directly inside the Worker script.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/return-html)

import { Render, TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/return-json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ description: Return JSON directly from a Worker script, useful for building APIs
and middleware.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/return-json)

import { Render, TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/rewrite-links.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ description: Rewrite URL links in HTML using the HTMLRewriter. This is useful
for JAMstack websites.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/rewrite-links)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/security-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ description: Set common security headers (X-XSS-Protection, X-Frame-Options,
Strict-Transport-Security, Content-Security-Policy).
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/security-headers)

import { TabItem, Tabs } from "~/components";

<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/workers/examples/signing-requests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ sidebar:
description: Verify a signed request using the HMAC and SHA-256 algorithms or return a 403.
---

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/signing-requests)

import { TabItem, Tabs } from "~/components";

:::note
Expand Down