# Custom domains

Every Dina app gets a default URL like `https://my-app.dina.run`. That's great for testing, but most real products want to live under their own domain. A **custom hostname** (sometimes called a custom domain) lets visitors reach your app at `app.yourcompany.com` instead.

Attaching a custom hostname is a two-step dance:

1. Tell Dina about the hostname.
2. Point your domain's DNS at the app.

The order doesn't matter — but both have to be done before visitors can load the site.

## 1. Add the hostname to your app

```sh
dina apps hostnames add --app my-app api.example.com
```

Dina records that this app should answer to that hostname and issues a TLS certificate for it once DNS is set up.

You can attach multiple hostnames to the same app:

```sh
dina apps hostnames add --app my-app api.example.com
dina apps hostnames add --app my-app www.example.com
```

## 2. Point DNS at your app

In your DNS provider (Cloudflare, Namecheap, Gandi, wherever your domain lives), add a record pointing the hostname at your app's Dina URL.

If you need to look up your app's Dina URL:

```sh
dina apps info --app my-app
```

The simplest setup is a **CNAME** record pointing your hostname at the `dina.run` URL. If your DNS provider doesn't allow CNAMEs at the root of a domain (the so-called apex), use an `A` record instead — your provider's docs will walk you through it.

Changes usually propagate in a few minutes, sometimes longer. While you wait, Dina is automatically requesting a TLS certificate so `https://` works once DNS resolves.

## Verify it's working

```sh
dina apps info --app my-app
```

The `Hostnames` section lists every hostname attached to the app. In your browser, loading the hostname should show your app — not a certificate warning and not a "not found" page from Dina.

If the certificate isn't ready yet, wait a few minutes and try again. Certificate issuance requires DNS to resolve first.

## Remove a hostname

```sh
dina apps hostnames remove --app my-app api.example.com
```

The CLI asks for confirmation before unbinding the hostname. Skip the prompt in scripts with `--force`:

```sh
dina apps hostnames remove --app my-app api.example.com --force
```

Removing a hostname doesn't delete your DNS records — that's up to your DNS provider. Once the hostname is detached from the app, requests to it will no longer reach Dina.

## Common problems

**Browser shows a certificate warning.** DNS isn't resolving yet, or the certificate is still being issued. Give it a few minutes after changing DNS.

**Site loads but shows a 404.** The hostname might be pointed at the wrong app, or DNS is pointing at something other than your Dina app. Run `dina apps info --app my-app` to check the expected URL and compare it with what your DNS record actually returns (`dig api.example.com` or any online DNS lookup tool).

**"Already attached to another app".** A hostname can only belong to one app. Remove it from the other app first, or choose a different hostname.
