Can I use workers independent of my site hosted on AWS?

I have a number of users scarping my data and don’t have access to my server logs. Can I use CF workers within CloudFlare to monitor my site hosted on AWS? If so, is there a tutorial on how to do this?

I want to create a worker to initiate a JS challenge (or challenge) for users are likely to be scraping my data. Then, evaluate these users in my firewall events and choose what I want to do with them. Each of the following trigger (within workers) would be helpful to find these scrapers:

  1. of pageviews. Ex: >50 pageviews a day

  2. City or city and state. I can see the scrapers on Google Analytics.
  3. Pages per session. Ex: > 20 pages per session

That process would only work if the hostname of your AWS site is :orange: Proxied by Cloudflare.

Great, the site is proxied by Cloudflare.

This is what I can came up with based on
https://developers.cloudflare.com/workers/examples/block-on-tls

async function handleRequest(request) {
  try {
    const city = request.cf.city

    // Challenge users from the city "City Name" to log challenge in Cloudflare for later review?
    if (request.cf.city = "City Name") {
      **// How do I trigger the challenge here?**
    }

    return fetch(request)
  }
  catch (err) {
    console.error(
      "request.cf does not exist in the previewer, only in production",
    )
    return new Response("Error in workers script" + err.message, {
      status: 500,
    })
  }
}

addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request))
})

Questions:

  1. Does that look about right?
  2. How do I trigger the JS challenge or challenge from the IF statement?
  3. How do I deploy this for a specific website?
  4. How would you apply a challenge for pageviews or pages per session?

Thanks!