# Custom domains

Serve a deployed environment, or one of its functions, from a domain you
own. You run two commands; a person publishes two DNS records.

Needs a deployed environment of a published project. In an organization
with no published project, `domains add` exits 4 and `error.action` is
`spaceboy billing publish --project prj_...`. Development is free, so a
development environment takes a custom domain only once its own project is
published; until then it is served from its Spaceboy address.

## 1. Link the domain

```bash
spaceboy domains add app.example.com --project prj_... --target production
```

`--target` defaults to `production`. Pass `--env env_...` to name an
environment directly. The command prints the records to publish:

```
Publish these DNS records for app.example.com:
  1. Ownership verification (required before anything is served):
     TXT   <verification name>   "<verification value>"
  2. Point traffic at Spaceboy (pick one):
     CNAME app.example.com -> <platform hostname>   (subdomains)
     A     app.example.com -> <IP address>          (apex domains)
```

Hand these to your person; Spaceboy cannot change your DNS.

## 2. Wait until it is live

```bash
spaceboy domains check app.example.com --wait
```

Statuses: `PENDING_VERIFICATION` (TXT record not found yet),
`PENDING_DNS` (verified, traffic not pointed yet), `ACTIVE` (serving, with
a certificate), `ERROR`. `--wait` polls for up to 30 minutes
(`--timeout <minutes>`).

## A domain for an API

Serve one HTTP function instead of the web app:

```bash
spaceboy domains add api.example.com --project prj_... --target production --function api__request__v1
```

`--output <name>` serves one extra web output declared in
`repobot.deploy.json` (`webOutputs`) instead. Pass one of the two, not both.

## List and remove

```bash
spaceboy domains list
spaceboy domains remove app.example.com
```

Removing releases the certificate; you can then delete the DNS records.
