Cloudflare Workers Integration

Zero-latency AI bot detection — runs at the edge, before your origin.

Zero latency

Fire-and-forget — never slows your users

Global edge

Runs in 300+ Cloudflare data centers

Server-side detection

Bot logic stays private on BotWatcher servers

OPTION A

Manual setup (5 minutes)

1

Create a Cloudflare Worker

Go to Workers & Pages → Create in your Cloudflare dashboard, then choose Create Worker.

2

Paste the Worker code

Replace the default “Hello World” code with the snippet below, then click Save & Deploy.

export default {
  async fetch(request, env, ctx) {
    // Forward the request to your origin unchanged
    const response = await fetch(request);

    // Fire-and-forget: report the hit to BotWatcher
    ctx.waitUntil((async () => {
      try {
        const url = new URL(request.url);
        await fetch("https://api.botwatcher.pro/edge", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "x-api-key": env.BOTWATCHER_API_KEY,
          },
          body: JSON.stringify({
            site: env.BOTWATCHER_DOMAIN,
            path: url.pathname,
            method: request.method,
            ua: request.headers.get("user-agent") || "",
            ip: request.headers.get("cf-connecting-ip") || "",
            country: request.headers.get("cf-ipcountry") || "",
            city: request.cf?.city || "",
            region: request.cf?.region || "",
            referer: request.headers.get("referer") || "",
          }),
        });
      } catch {
        // Never block your traffic — silently swallow errors
      }
    })());

    return response;
  },
};
js
3

Add your API key as a secret

In your Worker settings, go to Settings → Variables & Secrets and add:

BOTWATCHER_API_KEY

Your API key (from the Setup tab in your dashboard)

Store as Secret

BOTWATCHER_DOMAIN

yourdomain.com

Never put your API key in plain-text code — always use a Worker Secret so it stays encrypted at rest.

4

Route the Worker to your domain

Go to Websites → your domain → Workers Routes and add a route matching yourdomain.com/* pointing to your new Worker. This means every request your visitors make passes through the Worker first.

or
OPTION B

One-click deploy

Deploy straight from the BotWatcher GitHub template. Cloudflare clones the repo, builds it, and prompts you to set your secrets — all in one flow.

Deploy to Cloudflare Workers

You'll be prompted to set BOTWATCHER_API_KEY and BOTWATCHER_DOMAIN during the deploy wizard.

Or deploy manually using Wrangler CLI:

name = "botwatcher-proxy"
main = "src/index.js"
compatibility_date = "2024-01-01"

[vars]
BOTWATCHER_DOMAIN = "your-domain.com"

# Store your API key as a secret (never in plain text):
# wrangler secret put BOTWATCHER_API_KEY
toml
$npm install -g wrangler
$wrangler secret put BOTWATCHER_API_KEY
$wrangler deploy
How it works

The Worker sits in front of your origin. When a request arrives, it immediately calls fetch(request) to forward it — your users never wait.

Simultaneously, using ctx.waitUntil, it POSTs the request metadata (path, user-agent, IP, country) to api.botwatcher.pro/edge. BotWatcher's server-side detector classifies the hit and stores it — the classification logic is never exposed to clients.

Errors from the reporting call are swallowed silently so your site is never impacted.

Set up? Head to your dashboard to see bot traffic roll in.