Files
ServerKit/frontend/src/services/attachDomain.js
T
Juan Denis 30a3bfda82 Add DomainField, one input for picking a domain
Every screen that asked for a domain had its own input: a copied
regex in service settings, a separate "give it a subdomain" modal, a
bare required field on the Domains page. DomainField offers a managed
subdomain (label + base domain) or the user's own domain, normalizes
what is pasted, and says what will happen with DNS before submit.
attachDomain() sends either kind to the right endpoint.

Service settings now has one add-domain flow instead of an attach
form plus a subdomain modal, and the Domains page add modal uses the
same field.
2026-10-03 21:16:02 -04:00

22 lines
760 B
JavaScript

import api from './api';
/**
* Attach what a DomainField reported to an app. A managed subdomain goes
* through give-subdomain (vhost plus, in per-site mode, the DNS record); any
* other hostname becomes a plain domain row. Throws on failure; returns the
* API response.
*/
export async function attachDomain(applicationId, name, info, { isPrimary = false } = {}) {
if (info?.mode === 'subdomain') {
const res = await api.giveSubdomain(applicationId, info.label, info.base);
if (!res?.success) throw new Error(res?.error || 'Failed to publish subdomain');
return res;
}
return api.createDomain({
name,
application_id: applicationId,
is_primary: isPrimary,
ssl_enabled: false,
});
}