These snippets do the same job as the Next.js middleware,
Cloudflare Worker and WordPress plugin.
If your language isn’t listed, port one of them, following the steps below.
What your handler does
On each request your handler either serves the optimized version of the page or passes through. Always fail open — if anything errors, serve your normal page.- Match the User-Agent against the crawlers returned by the
botsetendpoint. Not a known crawler → pass through. - Cloaking firewall. If the crawler is a search index (
isSearchIndex: Googlebot, Bingbot, Applebot) → always pass through. See Cloaking firewall. - Verify the crawler with the
cidrsthebotsetendpoint returns for it →IP_VERIFIEDif it verifies,UA_ONLYif not. - Check eligibility — verified, the crawler’s
purposeis enabled, and your serve mode is Live (default). - Serve the optimized version from the
artifactendpoint; if there is none, pass through. - Report the hit to the
telemetryendpoint without waiting for the reply.
The endpoints
All calls sendAuthorization: Bearer <your edge token>. Get the token in Agent Analytics: choose
Any other stack and click Connect edge, or open Setup if the site is already connected.
Base URL:
https://app.trybluemoon.com.
Snippets
Each snippet ships in shadow mode (log-only) — flipSERVE_MODE to "default" when
you’re ready to serve. Set your edge token as the AEN_EDGE_TOKEN environment variable.
- Node.js (Express)
- PHP (any framework)
- Ruby (Rack)
aen.js
server.js
nginx and Apache
nginx and Apache can’t verify crawlers or fetch the optimized version on their own — but they don’t need to. They already sit in front of an app. Two options:You already run an app (recommended)
You already run an app (recommended)
If nginx/Apache proxies to Node, PHP, Ruby, etc., just add the snippet above to that app.
The web server needs no changes — the request already reaches your handler.
nginx — route crawlers to a small sidecar
nginx — route crawlers to a small sidecar
Run the Node snippet as a tiny sidecar on The sidecar serves the optimized version to verified crawlers and, for anything it decides to
pass through, proxies back to your origin. The user-agent list is only a pre-filter: the
sidecar still does the verification and the cloaking firewall.
127.0.0.1:8788 and send only AI-crawler
user-agents to it. Everything else hits your origin unchanged.Apache — hand crawlers to a PHP handler
Apache — hand crawlers to a PHP handler
With In
mod_rewrite, route AI user-agents to a front controller that includes aen.php..htaccess
aen-entry.php, run the interceptor, then fall back to rendering your normal page:aen-entry.php
Test it
1
Trigger a real AI crawler
Open ChatGPT (or Perplexity) with browsing and ask it to look up your site.
2
Watch the hit land
The visit appears in Agent Analytics under Recent activity, marked Verified.
3
Go live
Flip
SERVE_MODE to "default" and redeploy. See Serve modes.