This Cloudflare Worker cookie-worker is a rust crate — you don’t deploy it
directly. Instead, use
this template
to create your own private repository containing just your configuration.
The template wires up the entry point and CI for you; all the banner logic
comes from the cookie-worker crate.
Click Use this template on the template GitHub page and choose Create a new repository. Make the repository private — your configuration will live here.
Your new repository contains:
| File | Purpose |
|---|---|
src/lib.rs |
Entry point — calls into cookie-worker |
Cargo.toml |
Declares the cookie-worker dependency |
wrangler.jsonc |
Worker name and build config |
config/cookie-banner.toml |
Your banner configuration |
.github/workflows/ |
CI to build and upload on every push |
Open wrangler.jsonc and change the name field to something unique within
your Cloudflare account:
{
"name": "my-site-cookie-worker",
...
}
Edit config/cookie-banner.toml to match your site’s language, message, and scripts.
See the Configuration page for a full reference.
At minimum you need a [banner.<locale>] section, a [buttons.<locale>]
section, and a [scripts] section. Commit the file — CI reads it and passes
it to the worker at deploy time. No secrets required for the configuration.
In your repository, go to Settings → Secrets and variables → Actions and add:
| Secret name | Value |
|---|---|
CLOUDFLARE_API_TOKEN |
A Cloudflare API token with Workers Scripts: Edit permission |
This is the only secret needed.
Commit your changes and push. The CI workflow will:
cargo fmt and cargo clippy checksconfig/worker.toml and upload a new draft version to CloudflareThe upload creates a draft — it does not go live automatically. To promote it, run:
wrangler versions deploy --name=<your-worker-name> --yes
Or deploy from the Cloudflare dashboard under Workers → your worker → Deployments.
Prerequisite: your site’s DNS must be managed by Cloudflare and the record must be proxied (orange cloud icon in the Cloudflare DNS dashboard). If your site is not behind Cloudflare’s proxy, workers cannot intercept its traffic.
The worker acts as a transparent proxy: it receives the request, fetches the page from your origin server, injects the cookie banner into HTML responses, and returns the result to the visitor. Non-HTML responses (images, scripts, JSON) are passed through unmodified.
To wire this up:
Set the Route pattern to match all pages on your site, e.g.:
example.com/*
wrangler.jsonc.From this point on, every request matching the route pattern runs through your worker. All HTML pages will have the cookie banner injected automatically.
To cut a versioned release, trigger the Tag a release workflow manually
from the Actions tab. It will bump the version in Cargo.toml, commit,
tag, and kick off the release workflow which builds, uploads, and creates a
GitHub Release.
wrangler dev --var "WORKER_CONFIG:$(cat config/cookie-banner.toml)"