Brainerce hosting
Publish a Next.js storefront to brainerce.app from the CLI or GitHub.
Brainerce hosting runs a Next.js storefront (the one npx create-brainerce-store creates, an older one, or any other Next.js project) so it can be published without a separate host. A site is served from <name>.brainerce.app, and optionally from the merchant's own domain. This page is for developers and AI coding agents. The merchant-facing version is Publish my shop with Brainerce hosting.
Hosting has no SDK method and no public API endpoint. You publish with the CLI scripts in the project or from GitHub, and you manage the site in the dashboard (Sales Channels → the channel → Hosting). The routes behind those tools are internal and may change: do not call them yourself, and do not build on them.
Rules that decide whether it works
- Paid plans only (Pro, Growth, Enterprise). A store on the Free plan sees the Hosting tab locked and cannot create a site. When a store drops to Free its sites are suspended; a suspended site can still be viewed and deleted, and it is released when the store returns to a paid plan.
- One hosted site per sales channel. The number of sales channels a plan allows is the number of sites. Brainerce can also cap the number of sites for one store.
- A person approves a publish in the dashboard. An API key, the dashboard assistant and the admin MCP connector cannot create a site, approve a CLI sign-in or connect a repository. A coding agent can run the command, print the approval link and wait for the merchant to approve it.
- The team member needs permissions. View store settings to see the tab, Manage integrations to change anything, and Manage API keys as well to approve a CLI sign-in or connect GitHub. By default the Owner and a Manager have all three; a Staff member has View store settings only (sees the tab, changes nothing) and a Viewer does not see it.
- The project must be a Next.js project (
nextinpackage.json), built for Cloudflare Workers by OpenNext (1.20.16). It does not have to come fromcreate-brainerce-store. Static sites and single-page apps (Vite, plain React) are not available yet, and there is no date for it:add-hostingrefuses a folder withoutpackage.jsonor withoutnext, and changes nothing. - Hosting does not edit code and does not fix a build error. It publishes what the project builds.
Publish from the command line
A store created with starter 1.101.0 or newer already carries the scripts. In the project folder:
npm run build:hosted # builds the archive (.hosted/artifact.tar.gz)
npm run deploy:hosted # builds if needed, uploads and publishes
npm run hosted:logout # forget the saved sign-in on this computerdeploy:hosted without a key signs in through the browser, the way wrangler login does. The first time it prints a link and a short code. The merchant opens the link, checks the code and approves. The approval issues a key that lasts one hour, is bound to that one site and can only publish. The code expires after ten minutes. The approval page can also create the site and choose its address in the same step.
Useful flags: --subdomain <name> (pre-fills the address of a first publish), --skip-build (upload the archive build:hosted made), --no-verify (skip the live check at the end), --strict (exit 1 when the live check fails), --no-remember (do not keep a saved sign-in).
Every system builds directly, Windows included. Docker is used only when you ask for it (--docker or BRAINERCE_HOSTED_DOCKER=1); --no-docker and BRAINERCE_HOSTED_DOCKER=0 win over that. On Windows the script prints one line that OpenNext does not officially support Windows and that the build should be left to finish. A direct Windows build worked on two real stores, and the Docker path was never proven on a real Windows run. If a Windows build fails, use WSL, --docker, or publish from GitHub.
Add hosting to an existing project
npx create-brainerce-store@latest add-hostingIt works on any Next.js project, an older starter store included. It classifies the folder (a store made from the Brainerce template and its version, or any other Next.js project), prints what it found, adds the scripts and the pinned build tools, and commits nothing. The only refusals: no package.json, and no next dependency. The old refusal for a template older than 1.93.0, or one missing auth-cookie.ts, hosted-read-cache.ts or sanitizer.ts, is gone. The command does not touch the cookie names or the auth routes.
The one source change is the sanitizer chain. A project whose server code imports isomorphic-dompurify or jsdom answers 500 on Workers (jsdom reads a stylesheet from the file system).
- A Brainerce-template store:
add-hostingaddssanitizer.ts, swapssanitize.tsandsanitize-html.tsto it, addssanitize-html, and removesisomorphic-dompurifyfrompackage.jsononly when nothing imports it any more. A wrapper is replaced only when it is byte-identical (line endings normalised) to a version the template once shipped. Any other file is never overwritten: the new version goes beside it as<file>.brainerce-newwith a note on what to merge (--forcedoes not override this). The changes are prepared in a temporary copy and checked first, the originals go to.brainerce-backup/<timestamp>/, and a second run changes nothing.next.config.tsis not edited. - Any other Next.js project: the source is never edited. The build stops and names the fix (use
sanitize-html).
A template fix reaches a published store only when its owner rebuilds and publishes again: the platform never rebuilds a merchant's store.
What the build checks on a generic project
build:hosted skips the template-only currency check on a project that is not made from the template, and stops, with one sentence and one fix each, on: a server import of jsdom or isomorphic-dompurify, child_process, a sharp import, no build script, and output: 'export'. A write to the file system is a warning in the log on a generic project, not a stop (it usually runs at build time, a seed or a sitemap script, and only fails if it runs while the site is serving); in a store made from the template it still stops. Only imports count (comments, package.json entries, tests and tool configs are ignored), so a project can still fail in a way this scan does not know about.
Not supported or not tested:
export const runtime = 'edge'routes, middleware that needs Node-only APIs, and the Next 16proxy.tsare not tested on OpenNext 1.20.16.- Next.js version: OpenNext 1.20.16 accepts Next 15.5.29 or newer, or 16.4.5 or newer. On an older Next the build stops before it installs anything, with the sentence "This project uses Next X; hosting needs Next 15.5.29 or newer (or 16.4.5 or newer). Upgrade next and push." (a project that already lists the build tools in its lockfile only gets a warning). Next 14 and earlier are not supported.
next build --no-lintis added only on Next 15 and older. - npm only: the build installs with
npm ci(ornpm installwithout a lockfile) and the image has no pnpm, yarn or bun. A project with only apnpm-lock.yaml,yarn.lockor bun lockfile is installed withnpm install(the log says which lockfile it found and that npm is used), which does not use the versions that lockfile pinned, and abuildscript that callspnpmoryarnfails with a sentence saying so. Fix: runnpm installonce, commit thepackage-lock.json, push. - The build cannot call other websites. The build sandbox reaches only the npm registry, Google Fonts, Brainerce's own API and its storage. A fetch to a CMS or any other API while the project builds (
generateStaticParams, a static page that fetches) fails with the sentence "The build tried to reach a website that is not allowed ... Fetch that data at request time instead." There is no setting to allow another host. - A
.npmrcis cut down. The remote builds read only install switches from it (legacy-peer-deps,strict-peer-deps,auto-install-peers,engine-strict,install-strategy,prefer-dedupe,package-lock,save-exact,fund,audit, andregistry=only for the public npm registry). Tokens, passwords, private or scoped registries and every other line are removed, so a private npm registry does not work..env*files are never uploaded: a committed.env.productionis not read, and the build gets only the variables the platform sets. - Time: the whole remote build (download, install, tool install, build) is stopped after about ten minutes and says it ran out of time.
- Not tested on a real older or non-template store from start to finish. The old-template behaviour is covered by fixtures built from the template's own history, not by a live store.
- Cookies on an older template store keep their old names (no
__Host-upgrade). The platform stripsDomain=from cookies at the edge. A store with plain cookie names is exposed to a cookie planted by another store's JavaScript on the same domain until thebrainerce.appPublic Suffix List entry is accepted, which is not done yet.
Publish from GitHub
The Hosting tab has a GitHub section. Two connections exist and they do different things.
| Connection | How | What publishes |
|---|---|---|
| Connect with GitHub | A GitHub App ("Brainerce Hosting") reads one repository, read-only, through a token for that repository only. | Publish now builds the latest commit of the default branch. Publish on every push (on by default) publishes each push to the default branch. A rollback switches it off. |
By name (owner/repository) | No App. A GitHub Actions workflow in the repository exchanges its GitHub identity token for a one-hour key. No secret is stored. | A push to main runs .github/workflows/brainerce-hosted.yml. No Publish now, no push switch. |
The "Connect with GitHub" button is hidden until Brainerce opens its GitHub App to every account. Until then use the connection by name or the CLI.
The repository needs a Next.js package.json at its top level. It does not need scripts/build-hosted.mjs or package-lock.json: the remote builder (Publish now, and the CLI's remote path) runs the platform's own copy of the build driver and never the project's scripts. Without a lockfile it installs with npm install --ignore-scripts, which is not reproducible (the build log says so), so a lockfile is still recommended. The builder gives the sales channel id, the API address, the store name and the currency to every variable the project did not define. Known failures read as a plain sentence: Worker too large, too many Worker files, one static file too large, too many static files, static files too large in total, a native addon (sharp or a .node file), child_process, jsdom or isomorphic-dompurify in the server code, a file write in a store made from the template, output: 'export', no build script, an unsupported Next.js version, npm that cannot resolve the dependencies (add legacy-peer-deps=true to a .npmrc), a package-lock.json that does not match package.json, a TypeScript error (Type error:), a pnpm, yarn or bun command that is not installed, and a build-time fetch to a host that is not allowed. A project in a sub-folder is not supported. The by-name workflow does run the project's scripts, so add-hosting --github-actions adds them. The App is installed on selected repositories only, so a new repository must be added to the installation in GitHub. For the by-name route, npx create-brainerce-store add-hosting --github-actions writes the workflow file. A private repository connected by name is confirmed by its first deploy, within seven days. Actions run under the merchant's own GitHub account and plan.
Addresses and your own domain
- A
brainerce.appname: 3 to 40 characters, lowercase English letters, digits and single dashes, no dash at either end. Taken, reserved and held names all read as "not available". The name is fixed when the site is created. SITE_URLis set by the platform from the site's main address, and the address is added to the channel's allowed addresses (allowedOrigins) for you. Do not setSITE_URLas a variable.- The channel's
domainfollows the site's main address. The main address is the site's own ACTIVE custom domain (the primary one, else the earliest activated), because thebrainerce.appaddress redirects there, otherwise thebrainerce.appaddress. After a publish, when a custom domain becomes Active, and when one is removed, the platform keepsdomainin step: an emptydomainis set tohttps://<main address>only on a LIVE channel (awww.prefix is dropped, as the dashboard does when it stores a domain); an emptydomainon a TEST channel stays empty on purpose, because a TEST channel with nodomainaccepts any request Origin and adomainwould restrict it to that domain plusallowedOrigins, so a developer calling the same channel fromhttp://localhost:3000would get a 403 (the hosted address is already inallowedOrigins); adomainthat equals one of this site's own addresses moves to the new main address in either mode; any otherdomainis never changed. The write is a compare-and-set, so a merchant's own edit wins, and it is best effort (it never fails a publish, an activation or a removal; the next publish repeats it). The channel's mode is never changed: the merchant switches it to LIVE, which needs adomain(the request is refused withLIVE mode requires a public https domain with a real TLDuntil one is set, and nothing fills it at that moment: set it to the site'sbrainerce.appaddress or the custom domain in the same update). The customer sign-in redirect, order confirmation links and product feed URLs readdomain. - A custom domain: type it in Domains, then add the CNAME record the tab shows (copy the target from the tab, never from another page). The status moves from waiting for DNS to issuing the certificate to Active. Up to five domains per site. Domains of
brainerce.comare refused. Publish a new version once the domain is Active so links in the site use it. A subdomain was tested end to end on staging; a bare root domain was not. - Not tested: a full purchase on a hosted store through a provider with a redirect or 3D Secure, on either address. A complete checkout with the sandbox payment was walked on a hosted store. Place a test order with the real provider in test mode on the address shoppers will use.
- A provider that POSTs the shopper back to the storefront is not supported. The shopper returns by a GET to
/payment-complete, and the provider's payment notice goes to the Brainerce backend, not to the storefront.
Environment variables and secrets
Managed in Hosting → Variables and secrets. Names are upper-case letters, digits and underscores, at most 64 characters, not starting with a digit. At most 50 per site, values up to 4,096 bytes. A name containing KEY, SECRET, TOKEN or PASSWORD is stored as an encrypted secret that can never be read back. A change takes effect after Apply changes, which publishes a new version without rebuilding. Reserved and refused: NEXT_PUBLIC_* (baked in at build time: change it in the project and publish again), SITE_URL, BRAINERCE_API_URL, ASSETS, IMAGES, and the prefixes CF_, CLOUDFLARE, HOSTING_ and __. Deleting a secret removes it from the running site at once, and an older version that used it can no longer be rolled back to.
Files over 5 MB
Hosting limits each static file to 5 MB and all static files together to 20 MB. The build stops and names the file and its size. Hosting does not shrink, convert or move files and does not raise the limit for one store.
What to do with a file that is too big (typically a hero video or a large photo). Do not shrink it unless the merchant asks, do not leave it in the project (public/ or anywhere else) and do not stop. Put it in the store's own media library and use the address Brainerce returns. By size:
- Under 5 MB: it stays in the project.
- 5 to 10 MB: upload it with
client.uploadMedia(file)(an admin API key with themedia:writescope; never put that key in the project) or on the dashboard Assets page (the media library, Files in Hebrew). A file is at most 10 MB there. JPEG, PNG, WebP, GIF and AVIF images are converted to WebP and scaled to 2048 px on the longest side, and MP4, WebM, MOV and M4V videos are stored as sent.uploadMedia({ sourceUrl })makes the server fetch a remote image instead. It returnsasset.url. The route allows 20 requests per 5 minutes, and a 403 can also mean the plan's storage is full. - Over 10 MB: use the dashboard Assets page (Upload files, then Copy URL). It uploads straight to storage and takes videos of up to 5 GB. An AI coding agent cannot click in the dashboard and there is no API for this size, so say it in one sentence: ask the merchant to upload the file on the Assets page and paste back the file's address. Do not invent an API for it.
- When the Brainerce admin MCP is connected,
upload_media_assetandingest_media_asset(fetches from a public link) put a file in the library andlist_media_assetsshows the returned address. No size is promised for them.
Then use that address in the code: <video src>, <source> or <img>, and delete the big file from the project. A plain <video> or a CSS background needs nothing else. If you show it with next/image, add the address's host to images.remotePatterns in next.config. Compressing, or a video service such as Vimeo or YouTube, are alternatives, after the media library. The merchant-facing version: Big videos and large images.
Versions and rollback
The last ten versions are kept. A version marked ready can be rolled back to from the Hosting tab; it is live within about a minute and the previous live version stays available to roll forward. A version that used a revoked secret cannot be returned to. A rollback does not undo anything in the Brainerce store.
Usage, allowances and cost
The Hosting tab shows requests, failed requests and processing time, refreshed once a day from a Cloudflare sample. It is a trend and a warning, not a bill. No monthly allowance is enforced and hosting is not billed separately yet, and there are no per-plan promises about CPU time or traffic. The platform may add allowances later. Every site has per-request limits of 5,000 ms of CPU and 200 subrequests, and a shopper or a store that floods the API is throttled.
See also
- Publish my shop with Brainerce hosting for the merchant's steps.
- Core integration and Rules and reference for the storefront itself, including Origin rules.