Server & Environment Configuration
Complete configuration reference for brick() server options, environment variables, and secrets.
This reference documents all configuration options for the brick() HTTP server runtime, CLI environment variables, and secrets management.
Project and tooling settings (entry, paths, dev, build, gen and lint) live in brick.config.ts; runtime behaviour stays in brick().
CreateServerOptions for brick()
When constructing the server gateway via brick(options), configure the following settings:
| Option | Type | Default | Description |
|---|---|---|---|
port | number | undefined | Accepted by the type but not read by brick(). Pass the port to app.listen(port) instead. |
prefix | string | "/api" | Base path for every action, resource, socket and plugin route: ${prefix}/<service>/<action>, ${prefix}/<service>/<resource>/.... See URL Scheme. |
services | Service[] | All registered services | Array of services to mount. Defaults to getGlobalRegistry().list(). |
title | string | "Brick-TS API Mesh" | Application title rendered in OpenAPI 3.1 and documentation headers. |
version | string | "1.0.0" | Application API version in OpenAPI info.version. |
description | string | undefined | Narrative API description for OpenAPI specifications. |
docs | boolean | true | Enables or disables the OpenAPI specification, Scalar, and Swagger UI routes. |
openApiPath | string | "/openapi.json" | Path where raw OpenAPI 3.1 JSON is served. Not affected by prefix. |
docsPath | string | "/docs" | Path where Scalar interactive API documentation is mounted. Not affected by prefix. |
swaggerPath | string | "/swagger" | Path where Swagger UI documentation is mounted. Not affected by prefix. |
requestLogging | boolean | RequestLoggingOptions | true | Logs METHOD path → status (ms) per request. Options: { enabled?: boolean; logger?: (msg: string) => void }. |
reference | boolean | ReferenceOptions | false | true mounts a Scalar page at /reference. Options mount one only with a path; documents adds OpenAPI documents to the dashboard's APIs tab. |
compiler | boolean | true | When true, plugins prepare their work at server construction (CRUD prewarms its statements); false skips that. |
compilation | CompiledApplication | undefined | Precompiled handlers (used by the bundle that brick build emits). |
secrets | { source?, validate? } | undefined | Secret source and boot validation. resolveSecrets() runs at construction unless validate: false. |
endpoints | EndpointDefinition[] | undefined | Raw HTTP routes mounted outside the JSON action mesh. |
cors | boolean | string | string[] | (origin, request) => boolean | { origin?, credentials? } | undefined | CORS for browser callers on other origins. Origins are compared exactly; others get no Access-Control-Allow-Origin. See CORS. |
dashboard | DashboardOptions | undefined | Read-only monitoring dashboard brick start serves on its own port, behind auth. Options: { port?: number; host?: string; auth?: { token?: string | string[]; authorize?: (request: Request) => boolean | Response | Promise<boolean | Response> }; historyDays?: number }. Required auth beyond loopback; turns on telemetry. See Monitoring Dashboard. |
documentation | string | DocumentationOptions | undefined | Folder of .md/.mdx pages shown in the brick dev dashboard's Docs tab. Options: { dir: string; components?: string }. Relative paths start at the app entry's folder. Needs fumadocs-core and @mdx-js/mdx. |
brick() always mounts GET /_health and GET /_brick/services at the root, regardless of prefix.
CORS
Browsers only let a page on another origin read your API when the response allows that origin. Set cors to name the origins:
export default brick({
services,
cors: { origin: "https://app.example.com", credentials: true },
});origin takes:
true(the default): only the app's own origin, as the browser sees it (it honorsX-Forwarded-ProtoandX-Forwarded-Host).- A string or an array: exact origins, such as
"https://app.example.com"."*"is refused at startup. - A predicate
(origin, request) => boolean, for rules such as preview deployments.
cors also takes the origin rule directly: cors: true, cors: "https://app.example.com", cors: [a, b] or cors: (origin) => ….
For an allowed origin, Brick echoes it in Access-Control-Allow-Origin and adds Vary: Origin. With credentials: true it also sends Access-Control-Allow-Credentials: true, so the browser sends cookies and reads the response. An origin that isn't allowed gets no CORS headers, and the browser blocks the call. Brick never reflects an origin the rule doesn't allow.
Preflight requests (OPTIONS with Access-Control-Request-Method) are answered with 204 before routing and plugin middleware, so a middleware doesn't refuse them. Responses from middleware carry the CORS headers too. An allowed preflight lists GET, POST, PUT, PATCH, DELETE and echoes the requested headers. CORS headers are also set on error responses, so the browser can read the error.
Environment Variables
The framework and CLI inspect the following environment variables:
PORT
- Used by:
brick dev,brick start, and compiled bundles (dist/brick/server.js).brick()itself does not readPORT. - Precedence: For
dev/start, an explicit--port <number>flag wins overPORT, which wins overdev.portinbrick.config.ts(brick devonly), which wins over the default4000. Compiled bundles usePORT, falling back to the--portvalue given tobrick build(default4000). - Constraints: Must be an integer between
1and65535. Out-of-range values or non-numeric strings make the process exit with an error.
Secrets Management (@brickkit/core)
Brick-TS includes a secret referencing utility. Each defineSecret() call registers a reference; values resolve from process.env (or a custom SecretSource) when you read them. A secret without a default is required:
import { defineSecret, resolveSecrets } from "@brickkit/core";
// 1. Declare references to environment variables:
export const dbPassword = defineSecret("DB_PASSWORD");
export const apiKey = defineSecret("STRIPE_API_KEY").default(""); // a default makes it optional
export const port = defineSecret("PORT").default("4000").transform(Number);
// 2. Access secrets at runtime:
const password = dbPassword.require(); // Throws if missing or invalid
const key = apiKey.value(); // Returns the value, or undefined when unset
// 3. Validate all declared secrets (brick() also does this at construction):
resolveSecrets(); // Throws one error listing every missing required secretSecretRef methods: .default(value), .transform(fn), .validate(fn), .url(), .value(source?), .require(source?), and .isSet(source?). listSecrets() returns { name, hasDefault, isSet } metadata without values.
Overriding Secrets in Tests
In integration tests, override secret values without mutating process.env:
import { overrideSecret, resetSecrets } from "@brickkit/core";
overrideSecret("DB_PASSWORD", "test-secret");
// Clears all overrides AND the secret registry:
resetSecrets();