feat(hosting): sites list their custom domains, and hosting.detach() removes them (#4651)

* feat(hosting): sites list their custom domains, attach names a moved domain's old site, and hosting.detach() removes domains

- puter-subdomains read/select return `custom_domains` ({ uuid, hostname,
  status }) per site, filled by a `site.customDomains` event listener. Only
  rows attached under the site's current owner count; the field is left out
  when the listener fails, so a failed lookup never reads as "no domains".
- The attach dialog's answer carries `previousSite` when the user moved the
  domain from another site, kept through a status check or switch to www.
- puter.hosting.detach(subdomain) opens the custom domain dialog in a
  remove-only mode (desktop message, frame, or popup) and resolves the
  domains the user removed, or []. Desktops advertise it as
  `custom-domains-detach`; older ones reject with not_supported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(workers): expect the sandbox-owner message create() throws now

create() rejects another user's sandbox app with "The sandbox app '…'
belongs to another user…" since the workers name-cap fix; the deploy test
still expected the old wording and failed on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Neal ShahandClaude Opus 5.5 authored and GitHub committed 2026-11-15 21:02:07 -05:00
1 parent 1c67f93726
commit 237ff84cc5
32 files changed
+753 -84

No files matched your search

+1
View File
@@ -192,6 +192,7 @@ These hosting features are supported out of the box when using Puter.js:
- **[`puter.hosting.update()`](/Hosting/update/)** - Update hosting settings
- **[`puter.hosting.delete()`](/Hosting/delete/)** - Delete a hosting deployment
- **[`puter.hosting.attach()`](/Hosting/attach/)** - Let the user connect their own domain to a website
- **[`puter.hosting.detach()`](/Hosting/detach/)** - Let the user remove the custom domains of a website
## Examples
+2
View File
@@ -32,6 +32,8 @@ A `Promise` that resolves to a [`CustomDomain`](/Objects/customdomain/) object f
A newly added domain resolves with `status` set to `pending`. Its `records` list the DNS records the user still has to set.
When the user moved the domain from another of their websites, its `previousSite` attribute names that website. The other website no longer has the domain.
On a website that is cross-origin isolated, the popup can't send its result back to your page, so the promise resolves `null` even if the user goes on to connect a domain in the popup.
## Errors
+75
View File
@@ -0,0 +1,75 @@
---
title: puter.hosting.detach()
description: Let the user remove the custom domains of a website hosted on Puter.
platforms: [websites, apps]
---
Opens a Puter dialog where the user removes custom domains from one of their websites.
The dialog lists the domains connected to the website. Removing a domain takes it off the user's account. It stops serving the website right away, and its monthly charge stops. To use the domain again, the user adds it again with [`puter.hosting.attach()`](/Hosting/attach/) and sets its DNS records.
Your app doesn't need any permission to call this method. The user makes the choice in the dialog, and your app only receives the domains they removed.
Inside Puter, the dialog is rendered by the desktop environment. On a website, a puter.com popup hosts the dialog and signs the user in first if needed. Puter's own apps on puter.com subdomains show it in a frame over the page instead, when the user is signed in to both.
## Syntax
```js
puter.hosting.detach(subdomain)
```
## Parameters
#### `subdomain` (String) (required)
The name of the website to remove domains from, such as `example` for `example.puter.site`. The website must belong to the signed-in user.
## Return value
A `Promise` that resolves to an array of [`CustomDomain`](/Objects/customdomain/) objects, one for each domain the user removed. The array is empty if the user closed the dialog without removing a domain.
To see which domains a website still has, read the `custom_domains` attribute of its [`Subdomain`](/Objects/subdomain/) object from [`puter.hosting.get()`](/Hosting/get/).
On a website that is cross-origin isolated, the popup can't send its result back to your page, so the promise resolves an empty array even if the user removes a domain in the popup.
## Errors
The promise rejects with an error whose `code` is one of the following:
- `invalid_argument` when `subdomain` is missing or empty.
- `not_available` in an environment that can't show a dialog, such as Node.js or a worker.
- `not_supported` inside a version of the Puter desktop that doesn't have the dialog.
## Examples
### Remove a custom domain from a website
```html;hosting-detach
<html>
<body>
<button id="detach">Remove a custom domain</button>
<script src="https://js.puter.com/v2/"></script>
<script>
document.getElementById('detach').addEventListener('click', async () => {
// (1) Pick a website of the user's that has a custom domain
const sites = await puter.hosting.list();
const site = sites.find((s) => s.custom_domains?.length);
if (!site) {
puter.print('None of your websites has a custom domain.');
return;
}
// (2) Let the user remove its domains
const removed = await puter.hosting.detach(site.subdomain);
if (removed.length === 0) {
puter.print('No domain was removed.');
return;
}
for (const domain of removed) {
puter.print(`Removed ${domain.hostname}<br>`);
}
});
</script>
</body>
</html>
```
+5 -1
View File
@@ -3,7 +3,7 @@ title: CustomDomain
description: The CustomDomain object containing the details of a domain connected to a website.
---
The `CustomDomain` object describes a domain the user owns that serves one of their websites hosted on Puter. The [`puter.hosting.attach()`](/Hosting/attach/) method resolves to it.
The `CustomDomain` object describes a domain the user owns that serves one of their websites hosted on Puter. The [`puter.hosting.attach()`](/Hosting/attach/) method resolves to it, and [`puter.hosting.detach()`](/Hosting/detach/) resolves to a list of them.
## Attributes
@@ -57,6 +57,10 @@ When the domain became active, in milliseconds since the Unix epoch, or `null` i
Who hosts the DNS of a root domain: `route53`, `godaddy` or `other`. Puter looks this up when a root domain is added, and only includes it in that response. Route 53 and GoDaddy can't point a root domain at another host name, so a root domain on either is added as its `www.` hostname (see `redirectFrom`).
#### `previousSite` (String, optional)
The name of the website the domain served before, when the user moved it from that website in the [`puter.hosting.attach()`](/Hosting/attach/) dialog. Only the result of [`puter.hosting.attach()`](/Hosting/attach/) includes it.
#### `redirectFrom` (String, optional)
The root domain that forwards to this `www.` hostname. A root domain hosted on Route 53 or GoDaddy is added as its `www.` hostname, and the user can switch any other root domain to `www.` in the dialog. The `records` then include an `A` record that forwards the root domain.
+10
View File
@@ -19,3 +19,13 @@ e.g. in `example.puter.site`, `example` is the subdomain.
#### `root_dir` (FSItem)
An FSItem object representing the root directory of the subdomain. This is the directory where the files of the subdomain are stored.
#### `custom_domains` (Array, optional)
The custom domains connected to the website, whether pending or active. Each one is an object with these attributes:
- `uuid` (String): the unique identifier of the custom domain.
- `hostname` (String): the domain, such as `www.example.com`.
- `status` (String): `pending`, `active` or `failed`, as on a [`CustomDomain`](/Objects/customdomain/).
The array is empty when the website has no custom domains. The attribute is missing when Puter couldn't look the domains up, so read a missing attribute as unknown rather than as no domains.
+6
View File
@@ -870,6 +870,12 @@ const examples = [
slug: 'hosting-attach',
source: '/playground/examples/hosting-attach.html',
},
{
title: 'Remove a custom domain from a website',
description: 'Let the user remove a custom domain from a website with Puter.js hosting API. Run and experiment with this example directly in the playground.',
slug: 'hosting-detach',
source: '/playground/examples/hosting-detach.html',
},
{
title: 'Publish a portfolio page',
description: 'Publish a page built from form input as a public website with Puter.js hosting API. Run and modify this example directly in your browser.',
@@ -0,0 +1,27 @@
<html>
<body>
<button id="detach">Remove a custom domain</button>
<script src="https://js.puter.com/v2/"></script>
<script>
document.getElementById('detach').addEventListener('click', async () => {
// (1) Pick a website of the user's that has a custom domain
const sites = await puter.hosting.list();
const site = sites.find((s) => s.custom_domains?.length);
if (!site) {
puter.print('None of your websites has a custom domain.');
return;
}
// (2) Let the user remove its domains
const removed = await puter.hosting.detach(site.subdomain);
if (removed.length === 0) {
puter.print('No domain was removed.');
return;
}
for (const domain of removed) {
puter.print(`Removed ${domain.hostname}<br>`);
}
});
</script>
</body>
</html>
+8
View File
@@ -612,6 +612,14 @@ let sidebar = [
source: '/Hosting/attach.md',
path: '/Hosting/attach',
},
{
title: '<code>detach()</code>',
page_title: '<code>puter.hosting.detach()</code>',
title_tag: 'puter.hosting.detach()',
icon: '/assets/img/function.svg',
source: '/Hosting/detach.md',
path: '/Hosting/detach',
},
],
},
{