Skip to main content
If your site runs on Cloudflare, you install the Agent Edge Network as a Worker that sits in front of your origin. It passes every request straight through to your site, except verified AI answer-engine crawlers, which get the optimized version of your page.
This is the drop-in Worker — a single self-contained file with no dependencies. It is the Cloudflare counterpart of the Next.js middleware. You do not need wrangler — you can deploy entirely from the Cloudflare dashboard (see the tabs below).

What the Worker does

On every request to your site, the Worker:
  • Passes through anything that isn’t a known AI crawler — your site behaves exactly as before.
  • Never touches search bots — Googlebot, Bingbot and Applebot always get your real page (the cloaking firewall).
  • Serves verified answer-engine crawlers — in default mode — the optimized version of your page instead of raw HTML. Crawlers that can’t be verified get your normal page (verification levels).
  • Reports every hit to Agent Analytics, so you see who crawled what and whether it was served.
When the Worker serves the optimized version, the request does not reach your origin.

Before you start

  • Your domain is on Cloudflare (DNS proxied — the orange cloud).
  • An edge token (format aen_...) from Agent Analytics in the Bluemoon app: choose Cloudflare and click Connect edge, or open Setup if the site is already connected.
  • The worker.js file below.

The Worker code

This is the single file you deploy. It ships in shadow mode (log-only, serves your normal page) — change SERVE_MODE to "default" when you’re ready to serve.
worker.js

Deploy it

Pick whichever you prefer — both do exactly the same thing.
The fastest path if you’d rather not touch a terminal.
1

Create the Worker

In the Cloudflare dashboard, go to Workers & Pages → Create → Create Worker, name it (e.g. bluemoon-aen), and click Deploy. Then click Edit code, replace the starter code with the worker.js above, and Deploy again.
2

Add your edge token as a secret

Open the Worker → Settings → Variables and Secrets → Add. Choose Secret (encrypted), name it AEN_EDGE_TOKEN, paste the edge token from Agent Analytics → Setup, and Deploy.
3

Put it in front of your site

Settings → Triggers → Routes → Add route → enter yourdomain.com/* and pick your zone. The Worker now runs on every request to your site.

Test it

The Worker ships in shadow mode — it serves your normal page to everyone and only logs what it would have served, so there is zero risk while you validate.
1

Trigger a real AI crawler

Open ChatGPT (or Perplexity) with browsing and ask a question that makes it look up your site.
2

Watch the hit land

The visit appears in Agent Analytics under Recent activity, with the crawler’s name, marked Verified.
3

Go live

Once you see verified hits, change SERVE_MODE to "default" and redeploy (paste + Deploy, or wrangler deploy). Verified answer-engine crawlers now get the optimized version. See Serve modes.

Troubleshooting

Confirm the route covers your site (yourdomain.com/*), the AEN_EDGE_TOKEN secret is set, and you actually triggered a browsing AI. Opening your site in your own browser does not create a hit.
That’s expected in shadow mode, and for every human visitor in any mode — the Worker only changes the response for verified AI crawlers. To confirm it’s running, check the Worker’s logs in the Cloudflare dashboard while a crawler visits.
The request must be Verified (IP_VERIFIED), the crawler’s purpose must be enabled, and Bluemoon must have an optimized version of that URL. Check the page’s status in Agent Analytics.
No. Human and search-bot traffic passes straight through, and hit reporting never delays the response.

How it differs from the Next.js middleware

  • The Worker runs in front of your origin. Requests it passes through go straight to your origin without running the Worker again, so there is no loop.
  • It reads the visitor IP from Cloudflare’s cf-connecting-ip header.
Everything else — the cloaking firewall, verification levels and serve modes — behaves exactly as it does for the middleware.