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/cloudflare-for-platforms/workers-for-platforms/get-started/configuration.mdx
+21-4Lines changed: 21 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,17 +67,33 @@ To upload and deploy the user Worker to the dispatch namespace, running the foll
67
67
npx wrangler deploy --dispatch-namespace testing
68
68
```
69
69
70
-
### 4. Create a dispatch Worker
70
+
### 4. Create a dynamic dispatch Worker
71
71
72
-
[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.
72
+
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.
73
+
74
+
#### Why use a dynamic dispatch Worker?
75
+
76
+
***Scale**: Perfect for routing thousands or millions of hostnames to different Workers, without needing to rely on [Workers Routes](/workers/configuration/routing/routes/)
77
+
***Custom routing logic**: Write code to determine exactly how requests should be routed. For example:
78
+
* Map hostnames directly to specific Workers
79
+
* Route requests based on subdomains
80
+
* Use request metadata or headers for routing decisions
81
+
82
+
***Add platform functionality**: Build in additional features at the routing layer.
83
+
* Run authentication checks before requests reach user Workers
84
+
* Sanitize incoming requests
85
+
* Attach useful context like user IDs or account information
86
+
* Transform requests or responses as needed
87
+
88
+
**To create your dynamic dispatch Worker:**
73
89
74
90
Navigate up a level from your user Worker's project directory:
75
91
76
92
```sh
77
93
cd ..
78
94
```
79
95
80
-
Create your dispatch Worker. In this example, the dispatch Worker is called `my-dispatcher`.
96
+
Create your dynamic dispatch Worker. In this example, the dispatch Worker is called `my-dispatcher`.
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.
0 commit comments