> For the complete documentation index, see [llms.txt](https://s2tools.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://s2tools.gitbook.io/docs/boost-bot-v2/custom-domain.md).

# Custom Domain

In this section, you will have a detailed explanation on how to link your own custom domain to use for redeem and live stock website.

Before you start, make sure your domain is on cloudflare. You can follow this [tutorial](https://developers.cloudflare.com/fundamentals/manage-domains/add-site/) to add your domain to cloudflare for free.

#### Step 1: Create a Worker <a href="#step-1-create-a-worker" id="step-1-create-a-worker"></a>

1. On Cloudflare dashboard, click **Compute**
2. Go to **Workers & Pages**
3. Click **Create Application**
4. Start with the **Hello World** template
5. Deploy the Worker once to create it

***

#### Step 2: Edit Worker Code <a href="#step-2-edit-worker-code" id="step-2-edit-worker-code"></a>

Replace the default code with the following:

```javascript
const origin = "api.s2tools.uk";

export default {
  async fetch(request) {
    const incomingUrl = new URL(request.url);
    const customerHost = incomingUrl.hostname.toLowerCase();

    const originUrl = new URL(request.url);
    originUrl.protocol = "https:";
    originUrl.hostname = origin;
    originUrl.port = "";

    const headers = new Headers(request.headers);

    headers.set("X-Forwarded-Host", customerHost);

    try {
      const upstreamRequest = new Request(originUrl, {
        method: request.method,
        headers,
        body:
          request.method === "GET" || request.method === "HEAD"
            ? null
            : request.body,
        redirect: "manual",
      });

      return await fetch(upstreamRequest);
    } catch {
      return new Response("Page Offline", {
        status: 502,
        headers: {
          "Content-Type": "text/plain",
          "Cache-Control": "no-store",
        },
      });
    }
  },
};
```

***

#### Step 3: Deploy the Worker Again <a href="#step-3-deploy-the-worker-again" id="step-3-deploy-the-worker-again"></a>

* After editing the code, click **Deploy** to publish the updated Worker.

***

#### Step 4: Link Your Custom Domain to the Worker <a href="#step-4-link-your-custom-domain-to-the-worker" id="step-4-link-your-custom-domain-to-the-worker"></a>

1. At the top left, click your **Worker Name**
2. Click **Domains**
3. Under **Custom Domains and routes**, click **Add Domain**
4. Select **Custom Domain**
5. Enter your domain, for example: `s2tools.uk`
6. Click **Add**

***

#### Step 5: Done! <a href="#step-6-done" id="step-6-done"></a>

Your Worker is now linked to your custom domain and will proxy requests to the specified API endpoints

***

### Final Configuration

To make this work with our program, you must input your domain into the tool's configuration file under `CustomDomain` in the following format:

`subdomain.yourdomain.com`

The following endpoints will be available for use:

* `https://subdomain.yourdomain.com/stock`
* `https://subdomain.yourdomain.com/redeem`
* `https://subdomain.yourdomain.com/orders/{orderId}`

## Resources

<table data-column-title-hidden data-view="cards"><thead><tr><th data-card-target data-type="content-ref"></th><th data-hidden></th><th data-hidden></th><th data-hidden></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><a href="/docs/boost-bot-v2/resources.md">Resources</a></td><td></td><td></td><td></td><td><a href="https://content.gitbook.com/content/DQcxFZXv4HqFCxjWaDKh/blobs/5COquKCsSBYLIHgKSmmj/resources.png">resources.png</a></td></tr></tbody></table>
