Server foundations
Define and assemble Brix's server boundary, connect caching, and prepare the generated application for deployment.
Define and assemble the server
// src/brix.server.ts
"use server";
import { defineBrixServer } from "brix/server";
import { brix } from "./brix.ts";
export const brixServer = defineBrixServer(brix);
export const { createApiRoute, createFragment, createMarkdownIndexRoute, createPageRoute } =
brixServer;
// src/app.ts
import { createBrixApp } from "brix/server";
import { brixServer } from "./brix.server.ts";
export const app = createBrixApp(brixServer);
createBrixApp owns Hono construction, security and observability middleware, request IDs, assets, rendering, and safe errors. The generated production entry mounts discovered routes. Do not manually register conventional route modules.
defineBrixServer accepts application integrations including authentication, data cache, named edge cache policies, app state, global middleware, assets, renderer options, errors, security, service metadata, observability, locale resolution, translations, and Contentful preview.
Declare caching, do not implement it in routes
export const brixServer = defineBrixServer(brix, {
cachePolicies: ["publicPage", "sharedChrome"] as const,
dataCache: { namespace: "booking-production", store },
});
dataCache owns native GET reuse. Named cachePolicies are only edge hints selected by pages and fragments. Omitted route policies are uncached, and Brix never stores edge responses. See caching and fragments.
Translated responses must partition by visible locale. Localized paths are safe automatically; host-selected locale requires localePartition: "host"; cookie/header selection fails closed to uncached. See translations.
Deployment
For Lambda, configure defineBrixConfig({ platform: "aws" }). brix build emits the complete generated handler in dist/app.mjs; do not create a second source Lambda entry around src/app.ts.
Brix exposes supported Hono facades under brix/hono and related subpaths. Do not add another Hono dependency. Verify server changes with brix doctor, brix inspect routes, focused tests, and brix build. See API routes, environment, and testing.