# attach() · detach() · attachments()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/domain/attach/
Language: zh

`domain.attach({ host, name }) → Promise<Attachment>`

Puts something you host on IaGenify behind this domain — on the root, or on a name under it.

Status: one write path · root or subdomain · reads back what serves

```javascript
await domain.attach({ host: "hst_7f2" });                // example.com
await domain.attach({ host: "hst_7f2", name: "app" });   // app.example.com

await domain.attachments();
// [{ name: "example.com", host: "hst_7f2", kind: "site", label: "Showcase",
//    url: "https://example.com", status: "live", attachedAt: "…" }]

await domain.detach({ name: "app" });
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `host` | string | required | The host identifier, from [api.hosts](/zh/sdk/ref/hosts). |
| `name` | string | optional | A name under the zone. Left out, the root is attached. |

## Attaching is two halves, and you get both {#both-halves}

A serving name needs the DNS record *and* the recognition of that name by whatever answers it. This call goes through the same write path as [host.domains.attach()](/zh/sdk/ref/host/domains/attach): one plumbing, two points of view — from the domain, or from the host.

## Not the same thing as serve() {#serve}

[serve()](/zh/sdk/ref/domain/serve) points a name at a project of the account; `attach()` points it at a host created with [api.hosts](/zh/sdk/ref/hosts). Two targets, not two names for one thing — and a name set up with `serve()` does not appear in `attachments()`, which reads what the hosts carry.

## The address answers once the certificate is active {#certificate}

A fresh name takes from seconds to several minutes to get one, and the connection is refused until then. [tls()](/zh/sdk/ref/domain/tls) says where each attached name stands.

- [api.hosts](/zh/sdk/ref/hosts): Where a host comes from.
- [tls()](/zh/sdk/ref/domain/tls): Is the certificate up?
- [redirects](/zh/sdk/ref/domain/redirects): Sending www somewhere else.

```python
domain.attach(host="hst_7f2")                 # example.com
domain.attach(host="hst_7f2", name="app")     # app.example.com

domain.attachments()
# [{"name": "example.com", "host": "hst_7f2", "kind": "site", "label": "Showcase",
#   "url": "https://example.com", "status": "live", "attachedAt": "…"}]

domain.detach(name="app")
```
