---
title: "Domains"
description: "Attach custom hostnames to StackMachine apps."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.stackmachine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Domains

Domains let a StackMachine app answer from your own hostname. Add the hostname to an app, configure the expected DNS records, verify propagation, and optionally mark the hostname as the default app URL.

## Features

### Custom hostnames

Attach production, staging, or preview hostnames to the app record that serves your workload.

### DNS verification

StackMachine returns the records it expects. Add them at your DNS provider, then call `verify` once propagation is complete.

### Default domain selection

Use `isDefault` when a hostname should be treated as the primary URL for the app.

## Common workflow

1. Create the domain with the app ID and hostname.
2. Copy the returned DNS records into your DNS provider.
3. Call `client.apps.domains.verify` after propagation.
4. List domains to show the current set of attached hostnames.

## SDK examples

### Attach and verify a domain

Create a hostname, print the expected DNS records, verify the domain, and list attached hostnames.

```javascript
const domain = await client.apps.domains.create({
  app: "da_XYZ",
  hostname: "www.example.com",
  isDefault: true,
});

for (const record of domain.expectedDnsRecords) {
  console.log(record.host, record.recordType, record.value);
}

// Run this after the DNS records have propagated.
const verified = await client.apps.domains.verify(domain.id);
console.log(domain.hostname, verified);

const domains = await client.apps.domains
  .list({ app: "da_XYZ", limit: 10 })
  .autoPagingToArray({ limit: 25 });
console.log(domains.map((item) => item.hostname));
```

```python
from itertools import islice

domain = client.apps.domains.create(
    app="da_XYZ", hostname="www.example.com", is_default=True,
)
for record in domain.expected_dns_records:
    print(record.host, record.record_type, record.value)

# Run this after the DNS records have propagated.
verified = client.apps.domains.verify(domain.id)
print(domain.hostname, verified)

domains = list(islice(client.apps.domains.list(app="da_XYZ", limit=10), 25))
print([item.hostname for item in domains])
```

## Related docs

- [Add a custom domain](/apps/domains/add)
- [Delete a domain](/apps/domains/delete)
- [Get app by name](/apps/get-by-name)

> Source: [stackmachine/sdks](https://github.com/stackmachine/sdks/tree/main/js) JavaScript examples.

Source: https://docs.stackmachine.com/apps/domains/index.mdx
