Configuration
One optional file, brust.toml, next to package.json. Every key has a default; a missing file is fine, a malformed one stops the server with a message.
Where settings come from
For brust start, an environment variable beats a command-line flag, a flag beats brust.toml, and brust.toml beats the default. An empty variable counts as unset. When you start the server from your own file with run(), the config you pass takes the place of the flags: environment, then run({ config }), then brust.toml, then the defaults.
Server and workers
[server]
address = "127.0.0.1" # default localhost
port = 1337 # 1..65535, default 1337
max_loader_response_bytes = 8388608 # 256 KiB..64 MiB, default 8 MiB (env BRUST_MAX_LOADER_RESPONSE_BYTES)
base_path = "/portal" # mount the app under a path (a build setting), default the root
trailing_slash = "redirect" # "strict" | "redirect" | "ignore" (a build setting), default "strict"
stats = "token" # who may read /_brust/cache/stats: "off" (default), "public" or "token"
stats_token = "env:STATS_TOKEN" # with stats = "token": the variable that holds the bearer token
[workers]
count = 4 # 1..1024, default one per CPU core
slot_bytes = 262144 # 64 KiB..16 MiB, default 256 KiB (env BRUST_SLOT_BYTES)Each worker is a Bun thread that runs loaders, jobs and actions. Rust handles HTTP on its own threads, one per core by default.
Configure from code
brust start takes --port, --workers, --dist-dir and --entry, and nothing else. To set the rest without environment variables, call run() from your own file.
// server.ts: run it with 'bun server.ts' after 'brust build'
import { run } from '@brust/core'
await run({
distDir: 'dist', // default 'dist'
entry: 'routes.tsx', // the routes module; default 'routes.tsx'
config: {
host: '127.0.0.1', // default 'localhost'
port: 8080, // 0..65535 (0 = any free port); default 1337
workers: 4, // 1..1024; default one per CPU core
renderSlots: 4, // 1..64 per worker; default min(cores, 16)
ioThreads: 4, // 1..256 Rust I/O threads; default one per core
callTimeoutMs: 30_000, // a call still running after this answers 504
drainTimeoutMs: 10_000, // how long a graceful shutdown waits
bootTimeoutMs: 30_000, // start waits this long for every worker
slotBytes: 262_144, // one render slot's shared buffer; 64 KiB..16 MiB, default 256 KiB
maxLoaderResponseBytes: 8_388_608, // a bigger loader reply crosses by heap up to this; 256 KiB..64 MiB, default 8 MiB
},
})Build first with brust build, then start with bun server.ts. run() still reads brust.toml from the current directory, and an environment variable still wins over the value you pass. A value outside its range stops the start with a message that names it.
Once the server is up, run() does not return; the process lives until a signal drains it.
What only brust.toml sets
[cors] is read when the server starts, from brust.toml only. The config object of run() has no effect on it today.
[actions], [cache] and [build] are read by brust build and recorded in the manifest, so they are decided at build time. A build with no brust.toml has no actions and no shared cache, whatever server.ts says.
Trailing slashes
[server] trailing_slash decides what a page request whose path ends in / gets. "strict", the default, is the behaviour you had: the path is matched as written, so /cart/ is a 404 next to a /cart route. "redirect" answers a GET or HEAD with 308 to the same path without the slash, the query string kept and the base path too (/portal/ goes to /portal), before any route is matched or the page cache read. "ignore" drops the slash before matching: both spellings answer the same page from one cache entry. Other methods, / itself, a path ending in %2F, and brust’s own paths (/_brust/…, /public/…, /ping) are never touched.
Like base_path, it is baked into the manifest by brust build; a brust.toml or run({ config: { trailingSlash } }) that names another value stops brust start withtrailing-slash-mismatch. With --target static the static host serves the files its own way: the build warns trailing-slash-static unless the value is "strict".
Mount under a path
Two brust apps can share one origin when each one is mounted under its own path. Set [server] base_path = "/portal" and the app answers under /portal only. The value starts with /, has no trailing /, and each segment is letters, digits, ., _, ~ or -. Absent, empty or "/" is the root, and the build is the one you had before.
It is a build setting: brust build bakes it into dist/manifest.json, and the server answers under the base the manifest names. A brust.toml (or run({ config: { basePath } })) that names another one stops brust start with base-path-mismatch: rebuild. With none set, the manifest's wins.
Every URL brust owns moves below the base: /portal/_brust/client/… (scripts, stylesheets, islands, fonts and images the bundles import), /portal/_brust/action/… (the default actions prefix; an explicit [actions] prefix is used as written and has to lie under the base), /portal/_brust/cache/stats, /portal/public/… and /portal/ping. A path outside the base is a plain 404 from this app: it belongs to another one on the same origin. The routes, your links, navigate() and redirect() keep writing real URL paths, with the base: see Routing.
import { basePath } from '@brust/core' gives the value ('' at the root) on the server and in the browser, for code that builds URLs of its own. Read it inside your app's modules (routes, components, loaders), not in the file that calls run(): that file loads before the manifest's value is known. On Cloudflare the build bakes it into the Worker. A link to a path outside the base is a full page load, never a swapped fetch, so the app's SPA navigation stays inside its own subtree. To run two apps on one machine, see Deployment.
Try it
Set the pokedex server's port, worker count and actions; the file and the one-run override follow.
# pokedex/brust.toml
[server]
address = "127.0.0.1"
port = 1337
[workers]
count = 4
[actions]# the same, for one run, without editing the file
$ BRUST_PORT=1337 BRUST_WORKERS=4 bun run startResponse size
Every render slot is a 256 KiB shared buffer, and each worker has renderSlots of them. Memory for them is 256 KiB × render slots × workers: 4 workers with 4 slots each is 4 MiB.
A loader or job response has to fit its slot. The size counted is the JSON the loader or job returns (the page props and the job results), in UTF-8 bytes, not the HTML. One that does not fit fails the request with a plain 500, and the server's log carries the reason.
$ curl -si http://127.0.0.1:8080/big | head -1
HTTP/1.1 500 Internal Server ErrorERROR loader threw route=r1 error=response too large: 300029 > 262144The slot size is not configurable yet. Keep what a loader returns small: return what the page renders, and fetch the rest from an action.
Actions are different. An action body larger than the slot crosses by heap transfer, up to [actions] max_response_bytes (8 MiB by default); a bigger one is a 500 with brust: action response exceeds <max_response_bytes> bytes. Request bodies are capped by max_body_bytes (1 MiB by default).
The cache stats endpoint
/_brust/cache/stats reports cache sizes, hit rates and loader, job and worker call counts. It is off by default: the path answers 404, like any path nothing serves, so an app behind an edge that forwards every path does not publish its metrics on every domain it serves. [server] stats opens it: "public" serves the JSON to anyone, "token" serves it to a request with Authorization: Bearer <token> and answers 404 (not 401, so the endpoint is not revealed) to a wrong or missing one. A response that is served always carries cache-control: no-store, so an edge that caches everything does not keep it. brust dev defaults to "public". /ping stays public in every mode.
The token is never written in a file: stats_token = "env:NAME" names the variable that holds it, and brust start stops with a message naming the variable when it is unset or empty. The environment variable BRUST_STATS sets the mode too (it wins over the file); run({ config: { stats, statsToken } }) sets both from code. If you monitor an app with this endpoint, set stats = "public" or "token" when you upgrade. Workers has its own switch, [cloudflare] stats, and ignores [server].
Environment variables
| Variable | Range | Also in brust.toml |
|---|---|---|
BRUST_ADDR | non-empty | [server] address |
BRUST_PORT | 1 to 65535 | [server] port |
BRUST_WORKERS | 1 to 1024 | [workers] count |
BRUST_RENDER_SLOTS | 1 to 64 (default: cores, at most 16) | no |
BRUST_WORKER_THREADS | 1 to 256 Rust I/O threads (default: one per core) | no |
BRUST_BOOT_TIMEOUT_MS | default 30000 | no |
BRUST_CALL_TIMEOUT_MS | default 30000 | no |
BRUST_DRAIN_TIMEOUT_MS | default 10000 | no |
BRUST_STATS | off, public or token | [server] stats |
BRUST_DIST_DIR, BRUST_APP_ENTRY | paths | no (flags --dist-dir, --entry) |
Tier assertions
[tiers.max] says how heavy a component may get. Each key is a path pattern relative to the app root, with / between directories (* and ** as in a glob), and the value is the heaviest tier allowed. A #Export suffix picks one component of a file (#default is the default export). When several patterns match a component, one with #Export wins, then the longer one; two equally long patterns with different tiers are a config error. react allows anything.
A component in a [build] source_roots directory outside the app root is matched by its path from the app root, which starts with ../: "../shared/**" or "../shared/Stateful.tsx#Stateful".
A component that compiles heavier than its pattern allows fails brust build, for every target. The clones and React copies the compiler makes of a component for some call sites are checked under that component. A pattern that matches no component prints warning tiers "<pattern>" matches no component. [tiers] snapshot keeps a file with every component’s tier, and a build fails when one gets heavier than the file records. Both are described in Rendering tiers.
[tiers]
snapshot = "tiers.json" # optional: record every component's tier (path relative to the app root)
[tiers.max] # path pattern = the heaviest tier allowed: "static" < "native" < "react"
"components/views/**" = "static"
"pages/**" = "native"
"components/chat/Composer.tsx#Composer" = "react" # #Export picks one component of a file (#default)The other sections
[actions] turns actions on; see Actions. [cors] is read from the file only:
[cors]
origins = ["https://pokedex.example"] # required, at least one
methods = ["GET", "POST"]
headers = ["content-type"]
expose_headers = []
credentials = false # true with origin "*" is an error
max_age_seconds = 600[csp] sends a Content-Security-Policy header with every page (off by default); see Content Security Policy.
[build] server_only names modules that must never reach the browser; reaching one from client code fails the build with server-only-in-client.
[build]
server_only = ["lib/db", "bun:sqlite"] # import prefixes or app-relative paths kept out of the browser
source_roots = ["../shared"] # monorepo: directories beside the app that relative imports may reach
component_scripts = "drawn" # "route": every native chunk a route can draw, whatever the page drew[build] source_roots lists directories outside the app, relative to the app root, that its relative imports may reach: in a monorepo, import Button from "../shared/Button" compiles when ../shared is listed. Without it brust reads only the app’s own directory, and the import fails the build with unresolved-import (“it leaves the app root”). Each entry must be an existing directory; .. chains are normalised. The check is on the path as written, so an import that climbs out of a listed directory (../shared/../secret) is refused as well. Symbolic links are not followed when checking.
[build] template_max_bytes is a budget, in bytes, for one template the build writes. The default, 0, is no budget, and the build only warns about a template over 1 MB. With a budget, a template over it fails the build with one template-size error that lists every such template, largest first. The value must be a non-negative integer. In brust dev the error is a warning. See Large templates.
[build] component_scripts decides which native component chunks a page carries. The default, "drawn", sends the chunk of a component only when the page contains it (see Only the components the page drew). "route" sends every chunk the route can draw, whatever the page contains, as earlier versions did: use it if your own code inserts the markup of a native component the server did not render. Any other value is a config error.
[dev] watch is an array of files or directories, relative to the app root, that brust dev also reloads for (for example watch = ["../../packages/api"]). It only watches: unlike source_roots it does not change what imports may reach, and brust build and brust start ignore it. An unknown key or a non-string entry is a build error; a path that does not exist is a warning in dev. See Dev mode.
[cache] configures a shared cache adapter (see Cache adapters), and [cloudflare] the Workers target (see Workers target).
[cache]
adapter = "redis" # redis | dragonfly | cloudflare-kv | cloudflare-do | custom
[cache.redis]
url = "env:REDIS_URL" # always an env reference, never a literal URLbrust start has no TLS option. Put a proxy or a load balancer in front of it for HTTPS.