> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.squarecloud.app/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to set up your own domain (CNAME/DNS)

## 1. Prerequisites

Before starting the process, make sure you meet the following requirements:

* **Standard Plan or higher:** Square Cloud allows custom domain configuration only for users on the Standard plan or above.
* **A registered domain:** You must own a domain purchased from providers such as **Registro.br**, **Namecheap**, **GoDaddy**, **Google Domains**, or another registrar.
* **Cloudflare Account:** We will use Cloudflare to manage the DNS records, which ensures protection against DDoS attacks and faster loading speeds (CDN).

---

## 2. What are Nameservers?

Before configuring your website, you need to understand the concept of **Nameservers**.

> **Definition:** Nameservers act as the internet's "phonebook". They indicate which service is responsible for managing your domain's records. When you change your Nameservers to Cloudflare, you are telling the internet: "Cloudflare is now in charge of directing traffic to my website."

### Transferring management to Cloudflare

If your domain was purchased from Registro.br, GoDaddy, or another provider, you will need to point it to Cloudflare by following these steps:

1. Create a free account on [Cloudflare](https://dash.cloudflare.com/sign-up).
2. Click on **"Add a Site"** and type in your domain (e.g., `mywebsite.com`).
3. Cloudflare will provide two Nameserver addresses (e.g., `nina.ns.cloudflare.com` and `tom.ns.cloudflare.com`).
4. Access the control panel of your provider (where you bought the domain).
5. Look for the **Change Nameservers** or **DNS** option.
6. Replace the current addresses with the ones provided by Cloudflare and save.
7. **Wait:** Propagation can take from a few minutes up to 24 hours.

---

## 3. Configuration on Square Cloud

With DNS management now on Cloudflare, let's prepare your application on Square Cloud.

1. Access the [Square Cloud Dashboard](https://squarecloud.app/dashboard).
2. Select the application you want to link to the domain.
3. In the menu, click on the **Settings** tab and select the **Network** sub-tab.
4. In the text field, type your domain or subdomain (e.g., `mywebsite.com` or `api.mywebsite.com`).
5. Click **Save**.
6. The system will display the required records:
   * **CNAME:** A destination address (cname.squareweb.app).
   * **TXT (if generated):** A verification code to validate domain ownership.

---

## 4. Configuring Records on Cloudflare

Now, you need to copy the information from Square Cloud over to the Cloudflare dashboard.

1. In the Cloudflare dashboard, select your domain and go to the **DNS** > **Records** tab.
2. Click on **Add Record**.

### CNAME Record (Required)
* **Type:** CNAME
* **Name:** `@` (if it is the root domain) or your subdomain name (e.g., `www` or `app`).
* **Target:** cname.squareweb.app.
* **Proxy Status:** Keep it as **Proxied** (Orange cloud) to ensure SSL protection and security.

### TXT Record (If applicable)
* **Type:** TXT
* **Name:** `@` or the name indicated by the dashboard.
* **Content:** Paste the generated verification code.

---

## 5. Final Validation

After saving the records on Cloudflare, return to the **Network** tab on Square Cloud. 

* The system will check the records automatically. Once everything is correct, the domain status will change to **Active**.

---

## Redirecting www to your domain
* To redirect `www` to your domain, create a new record with the name **www** and type **A**, pointing to `192.0.2.1` (Cloudflare's internal dummy IP).
* Next, in Cloudflare, go to **Page Rules** and create a new rule: 
  * Setting: Forwarding URL
  * Status code: 301 Permanent Redirect
  * Destination URL: Your configured URL (e.g., https://mywebsite.com/)

## Troubleshooting Tips
* **Propagation:** If the website does not open, verify if the CNAME is correct using tools like [DNS Checker](https://dnschecker.org/).
* **Cache:** If you updated the records but do not see any changes, try clearing your browser cache or purging Cloudflare's cache under the **Caching** > **Configuration** > **Purge Everything** tab.