Host your users' projects
Use this guide if your platform deploys static sites for many users. Your backend creates a site for each user project, deploys the project, and later lists, rolls back, or deletes it.
The commands below use the leaf CLI from a backend job. For a single team’s CI pipeline, see CI and API keys. If your backend cannot run the CLI, deploy over HTTP instead; see the Deploy API reference.
Give each job only the scope it needs
Section titled “Give each job only the scope it needs”Create API keys with --can. Use one key per job, and store each key in the secret store of the job that uses it.
| Key | Allows | --site |
|---|---|---|
--can deploy | Deploy to sites and roll back. | Optional. Limits the key to one site. |
--can read | Read sites, deploys, and traffic. Usage (leaf usage) needs a read key without --site. | Optional. |
--can manage | Everything on the account: create and delete sites, manage sessions. | Not allowed. |
Creating and deleting sites needs a manage key. A manage key covers every site on the account, so keep it in your create and delete job only. Keys cannot create or revoke other keys. Create and revoke keys with leaf login as the account owner.
leaf keys create --name "site-admin" --can manage --expires 90dleaf keys create --name "deployer" --can deploy --expires 90dleaf keys create --name "monitor" --can read --expires 90dEach account can have up to 25 active keys, so you cannot create one key per user site. Use one deploy key for the deploy job. Keys expire after 1 to 365 days. The default is 90 days. Set LEAF_TOKEN to the key’s secret in the job’s environment. Never write it to a file or a log.
See API keys for the full key options.
Name sites
Section titled “Name sites”A site name is also its subdomain, so it must be unique across LeafCloud. A name must:
- Be 3 to 40 characters.
- Use only lowercase letters, digits, and hyphens.
- Not start or end with a hyphen.
- Not have a hyphen in positions 3 and 4.
- Not be only digits.
- Not be reserved or contain a blocked brand name.
The API returns an error when a name does not pass these rules. Pick another name and try again. See Sites and names.
Site names are unique across the whole platform, not just your account. Prefix each member’s name so one member cannot take another member’s name, for example acme-alice for member alice on the acme platform.
Create and deploy from a backend job
Section titled “Create and deploy from a backend job”Each job works in its own empty folder. Put the user’s project files in that folder, then write a leaf.toml that names the site. leaf deploy reads the site from leaf.toml when the account has more than one site.
site = "acme-landing"Create the site with the manage key. Pass --json to get the result as JSON:
leaf sites create acme-landing --jsonThen run the deploy with the deploy key. Dry run first. It builds nothing and uploads nothing:
leaf deploy --dry-run --jsonleaf deploy --yes --jsonRun leaf deploy from the project folder. It reads leaf.toml from the current folder.
Build safety
Section titled “Build safety”A deploy runs the project’s own build script, and --yes trusts it. The build runs on your server, so use a separate container or VM for each build, with no other users’ data and no secrets in the environment. leaf removes LEAF_* variables from the build process, but the build can still read anything else in the environment.
If you build in your own sandbox, skip the build step and deploy the output folder:
leaf deploy --no-build --dir dist --json--no-build skips the build and the dependency install. The --yes flag is then not needed.
leaf deploy runs the project’s install and build scripts like any build tool, so only deploy repositories you trust.
Deploy output
Section titled “Deploy output”On success, leaf deploy --json prints one JSON object:
| Field | Meaning |
|---|---|
url | The live address, for example https://acme-landing.leafcloud.app. |
deploy_id | The ID of this deploy. Use it with leaf rollback. |
status | live when the deploy is active. |
site | The site name. |
files | Number of files in the deploy. |
bytes | Total size of the files. |
uploaded_bytes | Bytes uploaded in this run. Present when files were uploaded. |
unchanged | true when the files match the live deploy, so nothing was uploaded. |
framework | The detected framework, or custom directory. |
build_command | The build command that ran, as an array. |
build_ran | Whether the build ran. |
propagation | Edge status for the deploy. |
With --dry-run --json, type is dry_run, and data holds framework, package_manager, site, build, build_ran, output_dir, output_exists, files, and bytes.
Exit codes and errors
Section titled “Exit codes and errors”With --json, a failure prints one object on stdout, for example {"schema":1,"error":"Daily deploy limit reached"}, and prints the message on stderr. Check the exit code first.
| Exit code | Meaning | Examples |
|---|---|---|
0 | Success. | The deploy is live. |
1 | Input or request error. | No site selected, secret-looking files found, a file or space quota error, a bad not_found value. |
2 | Not signed in, or the key is not allowed. | Missing LEAF_TOKEN, wrong scope, Site limit reached. |
3 | Local problem. | No framework detected, build failed, invalid leaf.toml, file over 25 MB. |
4 | Network, server, or rate limit. | Daily deploy limit reached, server error. Retry later. |
Parse each stdout line as JSON. Treat the deploy as successful only when the exit code is 0.
Archive deploys
Section titled “Archive deploys”To deploy a zip file, or one HTML page, in one request, send it to the archive endpoint instead of running leaf deploy on the user’s files:
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.zipContent-Typeisapplication/zipfor a zip, ortext/htmlfor one page. An HTML page is stored asindex.html.Idempotency-Keyis required. A retry of the same upload, with the same key, does not create a second deploy. Use a new key for each new upload. Reusing a key with different content returns409 idempotency_mismatch.labelsets the first part of the site’s address on your project-addresses domain. For example,label=alicegivesalice.sites.example.appon the domainsites.example.app. It is used only when the site is created, and defaults to the site name. On an existing site, leave it out or pass the label the site already has.not_foundchooses what a missing path serves.spa:index.htmlservesindex.htmlwith status200, for client-side routes.page:<path>serves that file from the upload with status404, for a custom error page.indexturns the fallback off, so a missing path is a plain404. The target must be in the upload.
When index.html loads a JavaScript bundle and there is no other HTML page, the endpoint sets not_found=spa:index.html for you. Pass a not_found query option to choose another fallback; index turns the automatic one off.
Put the zip’s index.html at the root, or put every file inside one top-level folder. With one folder and no file at the root, the folder’s contents become the site root. Two or more top-level folders are kept as they are, so / then needs a root index.html. __MACOSX/ entries, .DS_Store files, and root Thumbs.db or desktop.ini files are ignored.
The response is the finished deploy. It has site, created_site, unchanged, urls, files, bytes, not_found and spa. not_found is the fallback in effect. A deploy through the archive endpoint publishes and rolls back like any other deploy, and counts against the same limits.
When every archive slot is busy, the endpoint returns 429 archive_busy with a Retry-After header. A bulk import should run a few uploads at a time and retry a refused upload after that delay. A refused request created nothing.
Use a deploy key for this job, as in the sections above.
Put member sites on your own domain
Section titled “Put member sites on your own domain”Add a project-addresses domain, such as sites.example.app, and point *.sites.example.app at LeafCloud. Each member’s site then has an address like alice.sites.example.app. Use leaf domains add sites.example.app --project-addresses --all-projects, or the API with "kind": "platform". See Project addresses and the case study.
Submit your .app domain to the Public Suffix List. Browsers then treat each member site as its own site, so one member’s site cannot read another member’s cookies. Do it early: acceptance takes time. The case study has the full checklist in Before you open it to users.
List and delete sites
Section titled “List and delete sites”List the sites a key can see:
leaf sites list --jsonEach site is one line:
{"schema":1,"type":"sites","data":{"name":"acme-landing","url":"https://acme-landing.leafcloud.app"}}Delete a site with the manage key. Pass --yes in a job. Without a terminal, the command refuses to run unless --yes is set:
leaf sites delete acme-landing --yes --jsonOn success the output is {"schema":1,"deleted":true,"name":"acme-landing"}.
Deleting a site unpublishes every address, including its label on a project-addresses domain. The site name stays reserved for 30 days, so you cannot create a new site with that name during that time. The label is free at once, so another site can take it.
Deploy history and rollback
Section titled “Deploy history and rollback”List the deploys of a site:
leaf deploys --site acme-landing --jsonEach deploy is one line with type set to deploys. Its data includes deploy_id, status, created_at (Unix seconds), last_activity_at, and error.
Roll back to the previous deploy, or to a specific deploy ID:
leaf rollback --site acme-landing --jsonleaf rollback <deploy_id> --site acme-landing --jsonA rollback prints deploy_id, url, and status, with status set to live. Only deploys that LeafCloud keeps can be rollback targets. By default it keeps the last 5 deploys of each site.
leaf usage --json needs a read key without --site. It prints these fields:
sitesandsites_limitdeploys_todayanddeploys_today_limit, withresets_atfor the next resetstorage_bytesandstorage_limitbandwidth_allowance_bytesandbandwidth_month_bytesrequests_month
Limits
Section titled “Limits”These are the per-account limits for a new account. Contact us from Settings → Help & feedback in the dashboard to raise them for your account.
| Limit | Default | Error when reached |
|---|---|---|
| Sites per account | 5 | Site limit reached (exit 2) |
| Deploys per day | 100, reset at midnight UTC | Daily deploy limit reached (exit 4) |
| Storage for kept deploys | 250 MB | Deploy exceeds your storage quota (exit 1) |
| Files per deploy | 5,000 | Deploy exceeds the file count limit (exit 1) |
| Size of one file | 25 MB | File exceeds your 25 MB per file limit (exit 1), or the local check (exit 3) |
| Deploys kept per site | 5 | Older deploys cannot be rolled back to. |
| Project-addresses domains per account | 5 | account_domain_limit_reached. Remove one, or ask for more. See Domain limits. |
| Custom domains per project | 10 | domain_limit_reached. Remove one, or ask for more. See Domain limits. |
| Active API keys | 25 | Revoke an unused key before creating another. |
| Key lifetime | 1 to 365 days, default 90 | Invalid values are refused. |
| Bandwidth allowance | 100 GB per month | Shown in leaf usage. |
For pricing and fair use, see Pricing and limits.
Keep user content safe
Section titled “Keep user content safe”Secret scan. Before upload, leaf deploy checks each file in the output folder. It refuses the whole deploy when a file has a private-key block in its first 1 MB or has a credential file name. Do not use --allow-secrets for user content. The CLI has it, but only use it for files you are sure are public.
Untrusted code. Treat user projects as untrusted. Build each one in isolation, with time and memory limits. Do not read user files in your own backend process.
An abusive project. To take down a project that breaks your rules:
- Sign in as the account owner with
leaf login. Keys cannot revoke keys. - Save the record for your review:
leaf deploys --site <name> --json > record.json. - Delete the site:
leaf sites delete <name> --yes. - Revoke any key that deployed it:
leaf keys revoke <id>. - Send the site name and the reason from Settings → Help & feedback in the dashboard.
Deleting a site is permanent. Save the record first.