From 2c2fb0e3348524cd95eef58ef5ec60c7530624b6 Mon Sep 17 00:00:00 2001 From: dinasaur_404 Date: Wed, 15 Jan 2025 15:38:57 -0500 Subject: [PATCH 1/4] docs: improve dispatch Worker description --- .../get-started/configuration.mdx | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx b/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx index b1b2b66d2dbc931..4b209435ab5c895 100644 --- a/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx +++ b/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx @@ -67,9 +67,25 @@ To upload and deploy the user Worker to the dispatch namespace, running the foll npx wrangler deploy --dispatch-namespace testing ``` -### 4. Create a dispatch Worker +### 4. Create a dynamic dispatch Worker -[Dispatch Workers](/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/#dynamic-dispatch-worker) are used to execute user Workers from the dispatch namespace. You will now create a dispatch Worker and add logic it needs to route to the user Worker created in step 2. +A [dynamic dispatch Worker](/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/#dynamic-dispatch-worker) is a specialized routing Worker that directs incoming requests to the appropriate user Workers in your dispatch namespace. Instead of using [Workers Routes](https://developers.cloudflare.com/workers/configuration/routing/routes/), dispatch Workers let you programmatically control request routing through code. + +#### Why use a dynamic dispatch Worker? + +* **Scale**: Perfect for routing thousands or millions of hostnames to different Workers, without needing to rely on [Workers Routes](https://developers.cloudflare.com/workers/configuration/routing/routes/) +* **Custom routing logic**: Write code to determine exactly how requests should be routed. For example: + * Map hostnames directly to specific Workers + * Route requests based on subdomains + * Use request metadata or headers for routing decisions + +* **Add platform functionality**: Build in additional features at the routing layer: + * Run authentication checks before requests reach user Workers + * Sanitize incoming requests + * Attach useful context like user IDs or account information + * Transform requests or responses as needed + +**To create your dynamic dispatch Worker:** Navigate up a level from your user Worker's project directory: @@ -77,7 +93,7 @@ Navigate up a level from your user Worker's project directory: cd .. ``` -Create your dispatch Worker. In this example, the dispatch Worker is called `my-dispatcher`. +Create your dynamic dispatch Worker. In this example, the dispatch Worker is called `my-dispatcher`. @@ -121,8 +137,9 @@ export default { }, }; ``` +This example shows a simple dynamic dispatch Worker that routes all requests to a single user Worker. For more advanced routing patterns, you could route based on hostname, path, custom metadata, or other request properties. -Deploy your dispatch Worker: +Deploy your dynamic dispatch Worker: ```sh npx wrangler deploy From b75bcd7b27d97d1dc9cf0e9fa0141960c7d3e270 Mon Sep 17 00:00:00 2001 From: dinasaur404 <49571477+dinasaur404@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:19:09 -0500 Subject: [PATCH 2/4] Update src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Denise Peña <75506267+dcpena@users.noreply.github.com> --- .../workers-for-platforms/get-started/configuration.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx b/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx index 4b209435ab5c895..f601d696a259ab9 100644 --- a/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx +++ b/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx @@ -69,7 +69,7 @@ npx wrangler deploy --dispatch-namespace testing ### 4. Create a dynamic dispatch Worker -A [dynamic dispatch Worker](/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/#dynamic-dispatch-worker) is a specialized routing Worker that directs incoming requests to the appropriate user Workers in your dispatch namespace. Instead of using [Workers Routes](https://developers.cloudflare.com/workers/configuration/routing/routes/), dispatch Workers let you programmatically control request routing through code. +A [dynamic dispatch Worker](/cloudflare-for-platforms/workers-for-platforms/reference/how-workers-for-platforms-works/#dynamic-dispatch-worker) is a specialized routing Worker that directs incoming requests to the appropriate user Workers in your dispatch namespace. Instead of using [Workers Routes](/workers/configuration/routing/routes/), dispatch Workers let you programmatically control request routing through code. #### Why use a dynamic dispatch Worker? From 6d2277bd0d0e4edf88ab125848a816e4c74ec6f9 Mon Sep 17 00:00:00 2001 From: dinasaur404 <49571477+dinasaur404@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:19:15 -0500 Subject: [PATCH 3/4] Update src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Denise Peña <75506267+dcpena@users.noreply.github.com> --- .../workers-for-platforms/get-started/configuration.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx b/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx index f601d696a259ab9..1b52e5c7207b096 100644 --- a/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx +++ b/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx @@ -73,7 +73,7 @@ A [dynamic dispatch Worker](/cloudflare-for-platforms/workers-for-platforms/refe #### Why use a dynamic dispatch Worker? -* **Scale**: Perfect for routing thousands or millions of hostnames to different Workers, without needing to rely on [Workers Routes](https://developers.cloudflare.com/workers/configuration/routing/routes/) +* **Scale**: Perfect for routing thousands or millions of hostnames to different Workers, without needing to rely on [Workers Routes](/workers/configuration/routing/routes/) * **Custom routing logic**: Write code to determine exactly how requests should be routed. For example: * Map hostnames directly to specific Workers * Route requests based on subdomains From 5b69226144bea668bdcec542ad5a1304f527dd33 Mon Sep 17 00:00:00 2001 From: dinasaur404 <49571477+dinasaur404@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:19:26 -0500 Subject: [PATCH 4/4] Update src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Denise Peña <75506267+dcpena@users.noreply.github.com> --- .../workers-for-platforms/get-started/configuration.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx b/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx index 1b52e5c7207b096..cfd397c1a1ccbc3 100644 --- a/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx +++ b/src/content/docs/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx @@ -79,7 +79,7 @@ A [dynamic dispatch Worker](/cloudflare-for-platforms/workers-for-platforms/refe * Route requests based on subdomains * Use request metadata or headers for routing decisions -* **Add platform functionality**: Build in additional features at the routing layer: +* **Add platform functionality**: Build in additional features at the routing layer. * Run authentication checks before requests reach user Workers * Sanitize incoming requests * Attach useful context like user IDs or account information