> For the complete documentation index, see [llms.txt](https://docs.spindl.xyz/spindl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.spindl.xyz/spindl/techncial/javascript-sdk-html-script-guide/setup-a-reverse-proxy/using-cloudflare-workers.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
