cloudflare/workers-for-platforms-example
cloudflare/workers-for-platforms-example has 466 GitHub stars and 230 forks. GitHot measured 0 stars in 24 hours and +3 in 7 days. Last checked 2026-11-24 06:31 UTC. Last push 2026-04-23.
What you can do
- Simple Worker Creation: Web form for uploading Worker code
- Dynamic Dispatch: Route requests to user Workers by name
- KV Storage: Store friendly name mappings
- No Dependencies: Pure Workers runtime with minimal external dependencies
Gemessener Sternzuwachs
- in 24h
- 0
- in 7 days
- +3
- in 15 days
- Verlauf wird gesammelt
- in 1 month
- Verlauf wird gesammelt
Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.
Über uns
A great place for platforms to get started on Cloudflare Workers!
EntwicklerwerkzeugeREADME.md
OriginalWorkers for Platforms Example Project
This is a minimal Workers for Platforms example that demonstrates the core concepts of dynamic dispatch. The platform allows users to create and upload custom Workers through a simple web interface, then access them via friendly URLs.
Workers for Platforms gives your customers the ability to build services and customizations (powered by Workers) while you retain full control over how their code is executed and billed. The dynamic dispatch namespaces feature makes this possible.
By creating a dispatch namespace and using the dispatch_namespaces binding in a regular fetch handler, you have a "dispatch Worker":
export default {
async fetch(request, env) {
// "dispatcher" is a binding defined in wrangler.jsonc
// "my-user-worker" is a script previously uploaded to the dispatch namespace
const worker = env.dispatcher.get("my-user-worker");
return await worker.fetch(request);
}
}
This is the perfect way for a platform to create boilerplate functions, handle routing to "user Workers", and sanitize responses. You can manage thousands of Workers with a single Cloudflare Workers account!
In this example
Users can upload Workers scripts through a simple web form. The platform uploads the script to a dispatch namespace and stores a name → Worker ID mapping in Workers KV. Users can then access their Workers via URLs like /user-workers/my-worker.
This minimal example focuses on the core Workers for Platforms concepts:
- Dynamic dispatch using the
dispatcherbinding - Worker upload via the Cloudflare API
- Simple name-based routing using KV storage
Key Features
- Simple Worker Creation: Web form for uploading Worker code
- Dynamic Dispatch: Route requests to user Workers by name
- KV Storage: Store friendly name mappings
- No Dependencies: Pure Workers runtime with minimal external dependencies
Getting started
Your Cloudflare account needs access to Workers for Platforms.
Install the package and dependencies:
npm installCreate an API token with Workers Scripts (Edit) permission:
Visit https://dash.cloudflare.com/?to=/:account/api-tokens and create a new token with the "Workers Scripts (Edit)" permission.
Copy the
.env.testfile to.envand set theCLOUDFLARE_API_TOKENandCLOUDFLARE_ACCOUNT_IDsecrets:cp .env.test .envThen edit the
.envfile with your actual values:CLOUDFLARE_ACCOUNT_ID = "your_actual_account_id" CLOUDFLARE_API_TOKEN = "your_actual_api_token"The
.envfile is already in.gitignoreand will not be committed to git.Then run the following commands to add these secrets to your Worker in production:
npx wrangler secret put CLOUDFLARE_API_TOKENnpx wrangler secret put CLOUDFLARE_ACCOUNT_IDCreate a KV namespace for Worker mappings:
npx wrangler kv:namespace create "WORKER_MAPPINGS"Copy the namespace ID and preview ID into
wrangler.jsoncunder thekv_namespacesbinding.Create a dispatch namespace:
npx wrangler dispatch-namespace create workers-for-platforms-example-projectRun the Worker in dev mode:
npm run devOr deploy to production:
npm run deploy
Once the Worker is live, visit localhost:8787 in a browser. You can create a new Worker via the "/upload" link. Access your Workers at /user-workers/{name}!
Then access it at: http://localhost:8787/user-workers/my-worker
Ähnliche Projekte entdecken
Wird geladen…