# Using Cloudflare Workers

*Please use at least version **`1.6.0`** of* `@spindl-xyz/attribution` *or* `@spindl-xyz/attribution-lite` *for this feature.*

Make sure you're logged into [cloudflare](https://www.cloudflare.com/). Workers are really easy to set up and allow up to 100,000 **free** requests per day on the [free plan](https://developers.cloudflare.com/workers/platform/pricing/).&#x20;

### 1. Create a worker <a href="#id-1-create-a-worker" id="id-1-create-a-worker"></a>

From Cloudflare dashboard, select:  `Workers & Pages` > `Overview` > `Create application` > `Create Worker`. At this point, you can either keep the random worker name or choose your own. Click `Deploy` once done.

### 2. Configure as proxy

Click `Edit code` or `Quick edit` once the worker is set up and paste the code. You should now be seeing a code editor for the worker. You can copy/paste code below which will forwards the traffic and data to our server on `spindl.link`

```javascript
const API_HOST = "spindl.link"

async function handleRequest(event) {
    const url = new URL(event.request.url)
    const pathname = url.pathname
    const search = url.search
    const pathWithParams = pathname + search
    return forwardRequest(event, pathWithParams)
}

async function forwardRequest(event, pathWithSearch) {
    const request = new Request(event.request)
    return await fetch(`https://${API_HOST}${pathWithSearch}`, request)
}

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

When done, click "Save and deploy".

### 3. Configure Spindl SDK to use Proxy domain

Copy the `xxx.workers.dev` domain that you just created! Please make sure that domain doesn't include any common words that are more likely to be blocked by ad blockers including `track`, `analytics` and `spindl`

In the sdindl sdk configure object, paste the worker url as the `host`:

```javascript
spindl.configure({
  sdkKey: "<your SDK API key here>",
  host: "https://your-worker-url.workers.dev"
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.spindl.xyz/spindl/techncial/javascript-sdk-html-script-guide/setup-a-reverse-proxy/using-cloudflare-workers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
