Skip to content
brix.v2.15.0+b120c49

Search documentation

Loading search…

    Documentation menu
    Docs / Server configurationRead Markdown
    On this page

    Server configuration

    A full-stack Brix application has three server-facing files. src/brix.ts holds browser-safe contracts and configuration. src/brix.server.ts calls defineBrixServer(brix, options) to attach server-only concerns: environment, authentication, caching, security policy, middleware, logging, and integrations. src/app.ts calls createBrixApp(brixServer) to assemble the Hono application that the generated production entry serves with your discovered routes.

    Managed React applications are browser-only and have no Brix server; see application types.

    #
    1. Assemble the server and confirm a discovered route runs through the production app.
    2. Add authentication and security policy if any route is private, accepts mutations, or is called from another origin. Applications that sign in through brix-auth use its framework-owned policy.
    3. Add middleware, errors, and observability after the request boundary works.
    4. Choose a deployment target only after local route tests and brix verify pass.

    What happens on every request

    #

    createBrixApp installs infrastructure in a fixed order. Application options plug into specific steps; they cannot be reordered:

    1. Request ID. A valid incoming x-request-id is reused, otherwise Brix generates one, and it is returned on the response.
    2. Environment. When env is configured, the platform's environment snapshot is parsed. A failure returns a sanitized 500 and skips everything below except security headers.
    3. Logging and timing. The request logger, c.timings, and the request.start record begin.
    4. Security headers and CSP. Default secure headers and a fresh CSP nonce are applied to every response; Markdown and plain-text responses get a script-free policy without the nonce.
    5. Cross-origin mutation guard. Cross-origin browser POST, PUT, PATCH, and DELETE requests receive 403.
    6. Built-in assets. Production builds serve generated assets and public/ files before any route.
    7. Locale, then translations. resolveLocale and the translation loader run.
    8. Application middleware. Your middleware array runs in order.
    9. Routes. Integration and OpenAPI routes, then discovered routes. Each route applies its own body limit, authentication, and route middleware before the handler or loader.

    Responses also carry X-App-Version when a release version is known; see application version.