Deploy
Cartbase builds and hosts your storefront. You send the app's source files, one snapshot of the whole project, and Cartbase turns it into a running site: first on a permanent preview URL, then, when you press Publish (or call the publish endpoint), on the store's live domain. You never touch build servers, DNS, or hosting configuration; the platform provisions all of it the moment the store is created, and makes the first deploy itself: the store's starting point, a complete storefront on your own (still empty) catalog, already running on the preview link. Pull it with the CLI, change anything, deploy it back.
Two URLs exist per store, both created automatically:
| Surface | URL | What serves there |
|---|---|---|
| Preview | https://preview--{store-slug}.cartbase.net |
The newest deploy, always. The link never changes |
| Live | https://{store-slug}.cartbase.net |
The last published deploy, and nothing else |
A failed build never replaces what's live or what's on preview: the previous successful deploy keeps serving. Custom domains for the live site attach in the admin (Settings, Domains) and don't change anything on this page.
These are Admin API endpoints. They operate the store, so they
authenticate with an admin session (sign-in cookie) or the CLI's own
token, not the storefront headers the rest of this corpus uses. In
practice you'll deploy through the CLI (cartbase deploy), the admin UI
(Storefront in the sidebar), or an agent connection; all of them are
wrappers over exactly the calls below. Users who belong to several stores
name the target store with an x-cartbase-store: <client-id> header.
What a deploy is
A deploy is a full snapshot: the complete file tree of your storefront app. Snapshot semantics cut both ways: a file you stop sending is removed from the deployed site. There is no partial-update mode; your working directory is the truth, every time.
The snapshot travels as one archive, a gzipped tar of the app folder, which you put in storage on a link the platform signs for you, and then name in the deploy request. The archive never passes through the platform's API, so a deploy is bounded by the rules below and by nothing on the way.
Only what changed travels to your store's source. Every deploy is still a full snapshot, but the platform compares it with the version before it and writes only the files that differ, additions and removals, as one commit, whatever the file count. A deploy that changes three files costs three files, not the whole site; a deploy that changes nothing is still a version of its own. A very large change is written in a few commits and lands as one version, and two deploys sent at the same moment never interleave: the later one is written after the earlier one, as a snapshot should be. The deploy row and the CLI's last line say how many files travelled.
The bundle rules, enforced by the platform when it reads the archive:
- at most 1,500 files, 10 MB per file, 250 MB in total (unpacked sizes); a file over 10 MB is media, and media belongs in the store's Files
package.jsonmust exist at the bundle root: the app must be a buildable Next.js project (next build)- paths are relative to the app root, forward slashes; one wrapping folder
around everything (what
tarmakes from the parent folder) is taken off - never include:
node_modules/(dependencies install at build time),.next/(build output is generated),.git/, any.env*file - not allowed in storefront bundles:
middleware.*,app/api/orpages/api/routes, the hosting configuration file (vercel.json), which the platform owns, and the platform's ownproxy.tsandinstrumentation-client.js(they are added to every deploy for you; a pulled folder never contains them). A storefront is pages plus the@cartbase/storefrontpackage; server seams and hosting config are platform territory. The CORS proxy from the runbook is anext.configrewrite, which is fine.
Only the site goes in the folder. A data export, a database dump, a
spreadsheet, an archive: none of it belongs in a storefront's source, and
the snapshot would carry it into every version. The CLI refuses such a
file by name when it sits outside public/, and honours the folder's
.gitignore and a .cartbaseignore (same grammar) for everything else;
build caches like *.tsbuildinfo and editor droppings are left out by
default. Through the raw API you are the one leaving them out. Media that
the merchant changes belongs in the store's Files, served from the CDN,
not in public/.
Deploy to preview
Three calls, from any client:
1. Ask for an upload. POST /api/admin/storefront/deploys/uploads
answers 201 with where the archive goes:
{
"upload": {
"key": "deploys/<store>/<id>.tar.gz",
"url": "https://…signed…",
"method": "PUT",
"headers": { "content-type": "application/gzip" },
"expires_at": "2026-09-28T12:30:00.000Z",
"max_bytes": 262144000
}
}2. Put the archive there. One PUT to url, with exactly headers
and the archive as the body. No session, no other header: the link is
the credential, and it lives thirty minutes. The archive may be at most
max_bytes (the total ceiling above; gzip makes it smaller). It lands in
private storage that nothing serves, so your source never has a public
address, and it is removed after seven days; the platform's repository
holds the version.
3. Deploy it. POST /api/admin/storefront/deploys with the key:
# doc-noexec: admin-session auth; run from an authenticated context.
tar -czf storefront.tar.gz \
--exclude=node_modules --exclude=.next --exclude=.git --exclude='.env*' .
SHA=$(sha256sum storefront.tar.gz | cut -d' ' -f1)
UPLOAD=$(curl -s -X POST "$BASE/api/admin/storefront/deploys/uploads")
URL=$(echo "$UPLOAD" | jq -r .upload.url)
KEY=$(echo "$UPLOAD" | jq -r .upload.key)
curl -s -X PUT "$URL" -H "content-type: application/gzip" --data-binary @storefront.tar.gz
curl -s -X POST "$BASE/api/admin/storefront/deploys" \
-H "content-type: application/json" \
-d "{ \"archive_key\": \"$KEY\", \"sha256\": \"$SHA\", \"message\": \"homepage copy update\" }"Response 202:
{
"deploy": {
"id": "sfd_01J…",
"target": "preview",
"status": "queued",
"url": "https://preview--my-store.cartbase.net",
"message": "homepage copy update",
"file_count": null,
"created_at": "2026-08-03T22:41:00.000Z"
}
}sha256 is optional and recommended: the platform checks the archive it
reads against it. message (≤ 500 chars) is your label in the deploy
history; write what changed. source (api | cli | mcp | admin |
agent) tags where the deploy came from; omit it unless you're building
tooling. Hosting is provisioned when the store is born, so every call is
just a deploy; on a store whose hosting setup failed, the first call
resumes it (a few extra seconds).
The request answers at once; the archive is read, checked and committed
behind the answer, and the version is built once. Its status moves from
queued to building to ready, or ends failed or canceled. Follow
it with GET /api/admin/storefront/deploys/{id} until it is ready, then
open the preview URL. Builds of a small app land in roughly a minute.
A failed deploy says why. The row carries error_message, the cause in
the build's own words, and build_error, the build's error lines:
{
"deploy": {
"id": "sfd_01J…",
"target": "preview",
"status": "failed",
"url": "https://preview--my-store.cartbase.net",
"message": "homepage copy update",
"error_message": "Type error: Property 'title' does not exist on type 'Product'.",
"build_error": "Failed to compile.\n./src/app/page.tsx:12:5\nType error: Property 'title' does not exist on type 'Product'.",
"has_log": true,
"written_files": 1,
"written_bytes": 412,
"promoted_deploy_id": null,
"created_at": "…",
"switched_at": null
}
}GET /api/admin/storefront/deploys/{id}/log answers { deploy, log },
the whole build log as text. A deploy whose archive was refused after the
answer (a checksum that does not match, an archive that unpacks past the
ceiling, a bundle rule) carries its reason in error_message the same
way. The store's staff notification list is told by mail from Cartbase,
and nothing on preview or live changes.
A small app may still deploy inline, with the files inside the
request: { "files": [{ "path", "content_base64" }], "message" }. This
form is capped at 3 MB of files, because the platform's host caps one
request; past it the door answers 400 use_upload and points here. New
tooling should use the upload for every size.
Error codes you can hit, all readable 400s unless noted:
empty_bundle, bundle_too_large, invalid_bundle_file, invalid_path,
blocked_path, duplicate_path, invalid_encoding, file_too_large,
missing_package_json, use_upload, invalid_archive_key,
invalid_archive, archive_checksum_mismatch, and 404 archive_not_found when the key names nothing in storage (the link
expired, or the PUT never landed).
Environment: provided, not configured
Hosted storefronts receive their store's values automatically at build
time; do not put them in the bundle (.env* files are blocked
anyway):
| Variable | Value |
|---|---|
NEXT_PUBLIC_CARTBASE_PUBLISHABLE_KEY |
The store's publishable key, the one input a storefront needs |
NEXT_PUBLIC_CARTBASE_URL |
The platform origin (a constant; injected so a hosted build never guesses) |
NEXT_PUBLIC_CARTBASE_CLIENT_ID |
The store's id, the platform's own door; a storefront never needs to copy it |
Only these public values ever reach a storefront build; secret keys are never injected, so code that expects one is a design error.
The platform's checks on a built version
A build that succeeds proves that the app compiled, nothing more. Seconds after a version is built, the platform reads it on its own address, as a crawler would, and writes what it found on the version:
| Check | What is read | Fails when |
|---|---|---|
| The site | GET / |
the page is not 200, or the platform mark <meta name="generator" content="Cartbase"> is missing (the layout's metadata must come from createStorefrontMetadata) |
| The store API through the site | GET /api/store/store with the platform's own door |
the site answers its own page: the same-origin /api/store rewrite is missing, so the cart and the checkout in the browser reach nothing |
| The checkout page | GET /checkout |
the page is not 200, or Cartbase's checkout is not on it |
| The order page | GET /order/{a key no order has} |
the page answers 5xx |
| The analytics | GET /_cb/pageview |
the page answers 404: the platform's own files are not on this version |
The version carries verdict (ok, broken, or unchecked when the site
did not answer at all) and checks, one per row above with ok, detail
and, for a failed check, fix:
{
"deploy": {
"id": "sfd_01J…",
"status": "ready",
"verdict": "broken",
"checks": [
{ "id": "shell", "label": "The site", "ok": true, "detail": "The home page answers with the platform mark.", "fix": null },
{ "id": "store_api", "label": "The store API through the site", "ok": false, "detail": "The site answers /api/store with its own page: the same-origin rewrite is missing.", "fix": "next.config rewrites /api/store/:path* to the platform origin, so the cart and the checkout in the browser reach the store (the runbook, step 2)." }
]
}
}A broken version cannot be published. The publish door and the
schedule door answer 400 version_broken, the version's page in the
admin lists every check with its fix, the store's staff notification list
is mailed once per incident, and cartbase deploy, which waits for the
verdict after the build, prints the failed checks and ends with a non-zero
exit so an agent stops. The preview still shows the version: that is where
you look at it. An unchecked version is not refused; the platform could
not read the site, and says so.
Ejected components on a deploy
A file copied out of @cartbase/storefront with cartbase eject carries
a header naming the module, the package version, the kind and the reason.
The deploy reads every file for it and records what it found: the row
carries ejections ([{ path, module, package_version, kind, reason }]),
the store keeps one record per ejected path with when it was first and
last seen, and the staff notification list is mailed the first time a
wired piece (the checkout, the cart provider, the product hook, the API,
the tracking) leaves support. A copy made by hand carries no header and is
seen by nobody, which is why the command is the only way.
Overview: hosting status and deploy history
GET /api/admin/storefront returns the hosting record and the deploy
ledger, newest first:
# doc-noexec: admin-session auth.
curl -s "$BASE/api/admin/storefront"{
"storefront": {
"id": "sfp_01J…",
"status": "ready",
"production_url": "https://my-store.cartbase.net",
"preview_url": "https://preview--my-store.cartbase.net",
"last_error": null,
"created_at": "…"
},
"deploys": [
{
"id": "sfd_01J…",
"target": "preview",
"status": "ready",
"message": "homepage copy update",
"url": "https://preview--my-store.cartbase.net",
"source": "cli",
"file_count": 3,
"total_bytes": 1930,
"written_files": 1,
"written_bytes": 412,
"error_message": null,
"promoted_deploy_id": null,
"created_at": "…",
"updated_at": "…"
}
]
}written_files and written_bytes are what the deploy wrote to the
store's source: the files that changed since the version before, and
their size. They are null until the commit lands.
storefront is present from the store's birth (null only on a store
created before hosting-at-birth that has never deployed). status: "provisioning" / "failed" (with last_error) describe hosting setup,
not builds; a failed provisioning resumes automatically on the next
deploy attempt.
Read the storefront back
POST /api/admin/storefront/source/downloads answers 201 with a signed
link to the current storefront as one archive, the exact snapshot the next
deploy would replace:
{
"download": {
"version": "<opaque snapshot id>",
"url": "https://…signed…",
"bytes": 2289000,
"expires_at": "2026-09-28T12:10:00.000Z",
"platform_files": ["proxy.ts", "src/proxy.ts", "instrumentation-client.js", "src/instrumentation-client.js"]
}
}GET the link within ten minutes; it is a gzipped tar with one root
folder, in the same private storage as a deploy's archive, removed after
a day. Leave out the platform_files when you unpack: they are the
platform's, added to every deploy, and the deploy door refuses them by
name. cartbase pull does all of this.
GET /api/admin/storefront/source answers the same snapshot as JSON,
{ version, files: [{ path, content_base64 }] }, with the platform's files
already left out. It is the form for a small storefront: its answer is one
response, which the platform's host caps at 4.5 MB, and a storefront
larger than 50 MB unpacked is refused as 413 storefront_too_large.
Publish, and rollback
POST /api/admin/storefront/publish promotes a ready preview deploy
to the live domain. This is the only path to production; nothing deploys
straight to live, no matter who's asking.
# doc-noexec: admin-session auth.
# Bare POST publishes the newest ready preview:
curl -s -X POST "$BASE/api/admin/storefront/publish"
# Naming an older deploy id IS the rollback mechanism:
curl -s -X POST "$BASE/api/admin/storefront/publish" \
-H "content-type: application/json" \
-d '{ "deploy_id": "sfd_01H…older…" }'Response 201 is a new ledger row with target: "production" and
promoted_deploy_id pointing at the version it made live. Publishing is
a switch: the version was built when it was deployed, and the live domain
moves onto that same build, so what you looked at on preview is exactly
what goes live. The row answers status: "ready" with switched_at once
the live domain is on it, usually within a few seconds. A version whose
build is no longer kept is built once more first: the row then answers
status: "building", and you follow it with
GET /api/admin/storefront/deploys/{id} until it is ready.
A publish is refused in words when the version is still building or its
build failed (400 not_built), when another publish is in motion
(409 publish_in_progress), when the version is already live
(409 already_live), and when the platform cannot reach its host at that
moment (503 host_unavailable: nothing changed, try again). A publish
that fails says what became of the site in its error_message, and the
staff notification list is told.
Rollback is not a separate feature: publish any earlier ready deploy
from the history and the live site is that snapshot again, with nothing
rebuilt. Roll forward the same way.
The CLI does all of this
# doc-noexec: the CLI acts as the person signed in on this machine; run it from the store's folder.
cartbase deploy . --message "homepage copy update"
cartbase pullcartbase deploy reads the folder as the site it is (the ignore files,
the defaults, the platform's own files left out, a data file or a file
over 10 MB refused by name, a link refused rather than followed), prints
what it is about to send (the count, the size, the five largest files),
packs the archive, uploads it on the signed link, names it in the deploy
request, and polls the deploy until it settles, ending with how many
files changed since the last version. A refusal, from the desk or from
the platform, is always a sentence. cartbase pull downloads the archive
and unpacks it, without the platform's files.
Workflow summary
- Build locally against your store (the runbook).
- Deploy, then check the permanent preview URL.
- Iterate: every deploy replaces preview, live is untouched.
- Publish when it's right; the deploy history is your undo button.