Hosting your users' sites on your own domain
This case study describes how a site builder platform can host its users’ static sites under its own domain, and let each user bring a domain of their own. The platform is not named here. The steps are the ones it uses, and the same steps work for any platform that hosts sites for other people.
The platform has three parts:
- One domain of its own, such as
sites.example.app. Every user’s site gets an address under it. - A backend job that creates, deploys and deletes sites for users. It uses API keys with the smallest scope it needs. Host your users’ projects has the full set of steps.
- A custom domain per user, added through the API, when a user wants their own address.
Step 1: Add the platform’s domain
Section titled “Step 1: Add the platform’s domain”Give every user’s site an address under the platform’s domain. One project-addresses domain serves all of them:
leaf domains add sites.example.app --project-addresses --all-projectsWith --all-projects, every site gets its address at its first deploy. If only some sites should have an address, leave out --all-projects and add each site with --project. The API does the same with "kind": "platform", and "auto_include": true or a "projects" list. See Project addresses.
Add the records that the command prints at the platform’s DNS provider. The wildcard record *.sites.example.app sends every site address to LeafCloud, so you do not add one record per user. See Records to add.
Check it is live before you open the platform to users:
leaf domains show sites.example.appStep 2: Deploy from the backend job
Section titled “Step 2: Deploy from the backend job”A user uploads a site: a single HTML page, or a zip of files. The backend sends it to the archive endpoint, one call per deploy:
curl -fsS -X POST "https://api.leafcloud.in/v1/sites/$SITE/deploys/archive?label=$SITE" \ -H "Authorization: Bearer $LEAF_TOKEN" \ -H "Content-Type: application/zip" \ -H "Idempotency-Key: upload-$UPLOAD_ID" \ --data-binary @site.zip- Send
Content-Type: application/zipfor a zip, ortext/htmlfor one page. An HTML page is stored asindex.html. Idempotency-Keyis required. Use the same key when you retry the same upload, so a retry does not create a second deploy. Use a new key for a new upload.labelis set only when the site is created. Later deploys can leave it out.- The response is the finished deploy. It has
site,created_site,unchanged,urls(every address that is live),files,bytesandnot_found.
Use a deploy key for this job, or a key restricted to one site, and keep the secret in the job’s environment. Creating and deleting sites needs a manage key, which belongs in the job that creates and deletes sites. Never give users a key. Host your users’ projects explains the scopes.
The platform’s own limits apply to each deploy, such as the file count and the size of each file. If a user’s site needs more, ask for a higher limit from Settings → Help & feedback in the dashboard. See Limits for the domain limits.
Step 3: Give a user their own domain
Section titled “Step 3: Give a user their own domain”When a user adds a domain, the backend adds it to that user’s site:
curl -fsS -X POST "https://api.leafcloud.in/v1/sites/$SITE/domains" \ -H "Authorization: Bearer $LEAF_TOKEN" \ -H "Content-Type: application/json" \ -d '{"domain": "www.shop.example"}'The call returns the domain and the records to create. Show the user those records, with the target of the site, and the three names: the TXT record, the site record, and the _acme-challenge record. Records to add has what each one does.
Then poll the domain until it is live, or use --wait in the CLI. The states are the same as in the dashboard: waiting for DNS, getting a certificate, live, certificate failed, or DNS changed. Status and checks says what each one means and what to do. The MCP tools and the CLI handle the wait too. See Custom domains for AI agents.
A user’s domain is one custom domain of their site. Each site may have up to 10 custom domains by default. The account may have up to 5 project-addresses domains by default. See Limits.
Before you open it to users
Section titled “Before you open it to users”- Submit the platform’s domain to the Public Suffix List. The platform’s sites are on one domain, and browsers treat each site as a separate site once it is on the list. That stops sites from reading each other’s cookies. It takes time to be accepted, so do it early. See publicsuffix.org.
- Remove a user’s domain when the user leaves. Removing it stops the domain at once. The user’s site and its platform address keep working until you delete the site.
- Keep the
_acme-challengerecords that users add. Renewals need them.
What to remember
Section titled “What to remember”- One project-addresses domain covers every site, so you do not add a domain per user.
- The archive endpoint deploys one zip or one page per call. Use an idempotency key for every upload.
- Each user’s own domain is one custom domain of that user’s site. It is added and checked through the API.