Cloudflare edge Worker
Install
Three steps on your Cloudflare account. Before you start, check that the site's DNS records are proxied (orange cloud) and that SSL/TLS mode is Full (strict), or at least Full: Flexible sends traffic to your origin over HTTP.
1. Deploy the Worker#
From the Worker project Aiptimise sent you, with your Cloudflare account logged in:
npx wrangler login
npx wrangler deploy
npx wrangler secret put AIPTIMISE_SECRET # paste the secret when askedDeploy it under the Worker name Aiptimise gave you, which is already set in wrangler.jsonc. Never use a shared name: a second site in the same account would replace the first. The project has no routes, workers.dev URL or preview URLs: you add the route in step 3.
2. Check the variables#
wrangler.jsonc sets all of these except the secret. You can also see and change them in the dashboard: Workers & Pages → the Worker → Settings → Variables and Secrets.
| Name | Type | Value |
|---|---|---|
AIPTIMISE_SITE_ID | Text | Your site id. |
AIPTIMISE_SECRET | Secret | The secret. |
AIPTIMISE_BASE_URL | Text | https://app.aiptimise.com |
AIPTIMISE_EDGE_API_URL | Text | https://edge.aiptimise.com. Leave it unless Aiptimise asks you to clear it. |
AIPTIMISE_MODE | Text | shadow to start, on once checked, off to stop. |
After the first deploy, change a variable without touching routes by uploading a new version and deploying it (rollout takes about 20 seconds):
npx wrangler versions upload --var AIPTIMISE_MODE:on
npx wrangler versions deploy <version-id>@100% --yes3. Add the route, failing open#
Workers & Pages → the Worker → Settings → Domains & Routes → Add → Route:
- Zone: your zone.
- Route:
*example.com/*. One line covers the apex,wwwand every path. Aiptimise tells the Worker which hostnames and paths to act on; everything else passes straight through. - Request limit failure mode: Fail open (proceed). On the Workers Free plan (100,000 requests a day), fail closed serves an error page once the daily limit is reached. Fail open sends requests to your origin without the Worker instead.
Optional, for busy sites: add routes with no Worker for static paths (example.com/_next/*, example.com/static/*, …) so asset requests do not count as Worker invocations. Do not route hostnames that serve anything other than your public site: APIs, mail or admin panels on their own subdomains.
Before you switch it on
Cloudflare features that rewrite HTML or block bots run whether or not the Worker is there, and some of them undo its work. Go through Cloudflare settings next.