Skip to content

A domain for one project

Use a domain for one project when one site should answer at a domain you own, such as shop.example.com. The project’s <project>.leafcloud.app address keeps working next to it.

Dashboard: open Domains, choose Add domain, then choose For one project. Enter the domain and pick the project.

CLI:

TerminalTerminal windowbash
leaf domains add shop.example.com --project portfolio

API: POST /v1/sites/{name}/domains with the domain in the body:

{"domain": "shop.example.com"}

--wait keeps the command running until the domain is live, or stops when it fails:

TerminalTerminal windowbash
leaf domains add shop.example.com --project portfolio --wait

The command prints the DNS records to create. Add them at your DNS provider, then see Status and checks.

When you add example.com, LeafCloud also adds www.example.com, and the reverse. The two addresses form a pair. The pair shares one ownership record, and you add and remove them together.

What each address does depends on whether the project already has a primary address:

  • No primary yet. The address you typed becomes the primary, and it serves the project. Its partner is set to a redirect to it automatically, in the same step. Typing example.com makes the bare domain the primary and www a redirect to it. Typing www.example.com makes www the primary and the bare domain a redirect to it. You do not need a separate command for the redirect.
  • A primary already exists. Both addresses serve the project. Neither one redirects. Use the commands below if you want one of them to redirect.

A redirect answers 308 Permanent Redirect and keeps the path and the query string. A visit to example.com/about?x=1 goes to https://www.example.com/about?x=1 with a 308 status. Browsers and search engines treat it as a permanent move.

To choose the primary when the project has none yet, send "primary": "root" or "primary": "www" when you add the pair through the API. The CLI has no flag for this. With the CLI, add the pair, wait until it is live, then make the other address primary with the commands below.

You can change how any address is served later:

TerminalTerminal windowbash
leaf domains primary www.example.com # make it the project's primary address; it must be live
leaf domains redirect example.com # send visitors to the primary address
leaf domains serve example.com # serve the project here too, instead of redirecting

The primary address cannot be changed to a redirect or a serve directly. Make another live address the primary first.

API: POST /v1/domains/{domain}/route with {"route": "primary"}, {"route": "serve"} or {"route": "redirect"}.

A project may have several domains of its own, such as www.shop.com, shop.in and store.shop.com. Add each one with leaf domains add, or from the project’s page in the dashboard. Each domain has its own records and its own status.

There is a limit per project. See Limits.

TerminalTerminal windowbash
leaf domains remove shop.example.com

The command asks you to type the domain, unless you pass --yes. Removing one half of a www pair removes both halves. The project keeps its leafcloud.app address and its other domains. If you remove the primary address, another live address becomes the primary.

The certificate for a removed domain stops renewing. You can add the domain again later, on this project or another one.