forma-server
Axum middleware for the Forma Stack — server-side rendering, content-hashed asset serving, and CSP headers. Renders pages from FMIR binary IR without a JavaScript runtime.
Install
[]
= "0.1"
This pulls in forma-ir automatically.
What It Does
render_page(config)— generates a full HTML page from an IR module + slot dataload_ir_modules(manifest)— loads.irfiles from embedded assets at startupserve_asset(filename)— serves content-hashed assets with Brotli/gzip negotiation andCache-Control: immutablegenerate_nonce()— 256-bit cryptographically random nonce (ring CSPRNG)build_csp_header(nonce)— strict CSP: nounsafe-inline, nounsafe-eval, nonce-based scripts/styles
Quick Start
use ;
use Embed;
;
// At startup: load manifest and IR modules
let manifest = ;
let = ;
// Render a page
let page = render_page;
Two Rendering Modes
| Mode | What happens | When to use |
|---|---|---|
| Phase 1: Client Mount | Renders <div id="app"></div> — FormaJS mounts from scratch |
No IR available, or fallback |
| Phase 2: SSR Reconcile | Renders full HTML from IR walker — FormaJS hydrates | IR + slots available, fast first paint |
Security
- CSP headers: Strict policy with cryptographic nonces — no
unsafe-inline, nounsafe-eval - Nonce generation: 256-bit entropy via ring CSPRNG
- Asset serving:
rust-embedprevents path traversal — only compile-time embedded files are served - Template escaping: All interpolated values (URLs, class names, CSS) are HTML-escaped
- No unsafe code: Zero
unsafeblocks
When You Need This
Use it when: Your backend is Rust + Axum and you want the full Forma SSR pipeline with asset serving and CSP.
You don't need it if: You're only using FormaJS client-side (no Rust server), or you're using a non-Axum framework (use forma-ir directly).
Part of the Forma Stack
Frontend (TypeScript)
| Package | Description |
|---|---|
| @getforma/core | Reactive DOM library — signals, h(), islands, SSR hydration |
| @getforma/compiler | Vite plugin — h() optimization, server transforms, FMIR emission |
| @getforma/build | Production pipeline — bundling, hashing, compression, manifest |
Backend (Rust)
| Package | Description |
|---|---|
| forma-ir | FMIR parser, walker, WASM exports |
| forma-server | This crate — Axum middleware: SSR, asset serving, CSP |
Full Framework
| Package | Description |
|---|---|
| @getforma/create-app | npx @getforma/create-app — scaffolds Rust server + TypeScript frontend |
License
MIT