Configure Workers for Platforms
To enable Workers for Platforms, you will need to purchase the Workers for Platforms Paid plan.
- Log in to the Cloudflare dashboard ↗, and select your account.
- Complete the payment process for the Workers for Platforms Paid plan.
If you are an Enterprise customer, contact your Cloudflare account team to enable Workers for Platforms.
Refer to How Workers for Platforms works to learn more about Workers for Platforms terminology and architecture.
This guide will instruct you on setting up Workers for Platforms. You will configure a dispatch namespace, a dynamic dispatch Worker and a user Worker to test a request end to end.
First, create a user Workers. User Workers are Workers that your end users (end developers) will be uploading.
User Workers can be created using C3. C3 (create-cloudflare-cli) is a command-line tool designed to help you setup and deploy Workers to Cloudflare as fast as possible.
Open a terminal window and run C3 to create your Worker project. This example creates a user Worker called customer-worker-1
.
When following the interactive prompts, answer the questions as below:
- Select
no
to using TypeScript. - Select
no
to deploying your application.
Create a dispatch namespace. A dispatch namespace is made up of a collection of user Workers.
This example creates a dispatch namespace called testing
. To create a dispatch namespace, run:
Make sure you are in your user Worker’s project directory:
To upload and deploy the user Worker to the dispatch namespace, running the following command:
Dispatch Workers 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.
Navigate up a level from your user Worker’s project directory:
Create your dispatch Worker. In this example, the dispatch Worker is called my-dispatcher
.
For setup, select the following options:
- For What would you like to start with?, choose
Hello World example
. - For Which template would you like to use?, choose
Hello World Worker
. - For Which language do you want to use?, choose
JavaScript
. - For Do you want to use git for version control?, choose
Yes
. - For Do you want to deploy your application?, choose
No
(we will be making some changes before deploying).
Change to your project’s directory:
Open the wrangler.toml
file in your project directory, and add the dispatch namespace binding:
Add the following to the index.js file:
Deploy your dispatch Worker:
You will now send a request to the route your dynamic dispatch Worker is on. You should receive the response (Hello world
) you created in your user Worker (customer-worker-1
) that you call from your dynamic dispatch Worker (my-dispatcher
).
Preview the response to your Workers for Platforms project at https://my-dispatcher.<YOUR_WORKER_SUBDOMAIN>.workers.dev/
.
By completing this guide, you have successfully set up a dispatch namespace, dynamic dispatch Worker and user Worker to test a request end to end.
- Workers for Platforms example project ↗ - An end to end example project using Workers for Platforms