Skip to main content

forma_server/
lib.rs

1//! Axum middleware for Forma SSR.
2//!
3//! Provides page rendering (`render_page`), content-hashed asset serving,
4//! CSP headers with cryptographic nonces, service worker handling, and
5//! the Phase 1 (client mount) / Phase 2 (SSR reconcile) rendering pipeline.
6//!
7//! # Quick Start
8//!
9//! ```rust,no_run
10//! use forma_server::{render_page, PageConfig, RenderMode};
11//! ```
12//!
13//! # Serving a page
14//!
15//! [`PageOutput`]'s `html` and `csp` are a single unit — the HTML embeds a
16//! per-request nonce that only that policy blesses. Send them together with
17//! `Cache-Control: no-store` (see [`PageOutput::headers`]) and never cache the
18//! HTML across requests.
19
20// Makes README.md's and SECURITY.md's "Zero `unsafe` blocks" a property the
21// compiler enforces rather than a claim.
22#![forbid(unsafe_code)]
23
24/// Serving content-hashed files out of the embedded `dist` directory.
25pub mod assets;
26/// Content-Security-Policy construction and nonce generation.
27pub mod csp;
28/// Loading and version-checking the per-route `.ir` modules at startup.
29pub mod ir_compat;
30/// The service-worker response and its headers.
31pub mod sw;
32/// The HTML page template and the SSR render entry points.
33pub mod template;
34/// Request/response types: page config, manifest, render mode.
35pub mod types;
36
37/// Re-exported because it appears in [`assets::asset_bytes`]'s signature.
38pub use axum::body::Bytes;
39pub use csp::{build_csp_header, generate_csp_nonce, CspNonce, InvalidNonce};
40pub use ir_compat::{load_ir_modules, load_ir_modules_strict, IrLoadError};
41pub use template::{render_page, render_page_with_nonce};
42pub use types::*;