1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! Axum middleware for Forma SSR.
//!
//! Provides page rendering ([`try_render`]), content-hashed asset serving,
//! CSP headers with cryptographic nonces, an opt-in service worker ([`sw`]), and
//! the Phase 1 (client mount) / Phase 2 (SSR reconcile) rendering pipeline.
//!
//! # Quick Start
//!
//! ```rust,no_run
//! use forma_server::{try_render, PageConfig, PageResponse, RenderCtx, RenderError};
//! ```
//!
//! # Serving a page
//!
//! [`try_render`] returns the page or a coded [`RenderError`]; the handler
//! chooses the response. A page's HTML embeds a per-request nonce
//! that only its policy blesses, so the HTML, the policy and
//! `Cache-Control: no-store` travel together: a [`PageResponse`], as axum's
//! `IntoResponse`, writes all of them and cannot be sent without them.
//! A handler that needs a looser policy adds typed
//! [`PolicyExtensions`] through its [`RenderCtx`]; it never edits the
//! policy's text.
//!
//! ```rust,no_run
//! use axum::http::StatusCode;
//! use axum::response::{IntoResponse, Response};
//! use forma_server::{try_render, PageConfig, RenderCtx};
//!
//! fn home(config: &PageConfig) -> Response {
//! match try_render(config, &RenderCtx::new()) {
//! Ok(page) => page.into_response(),
//! Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
//! }
//! }
//! ```
//!
//! Markup the page carries unescaped is a [`RawHtml`], made only by
//! [`RawHtml::trusted`], so a search for that name finds every raw entry.
//! The route's `modulepreload` links come from the build's manifest
//! and head links have a typed field, both through [`RenderCtx`]; data goes
//! through `config_json`.
//!
//! Content nobody reviewed renders in the preview frame, whose document
//! [`PageResponse::frame`] writes ([`frame`]).
//!
//! A route the build declares `ssr: false` is served by
//! [`render_browser_shell`]. At start, [`load_ir_modules_strict`] is the
//! module loader: stop on its errors, before the port binds. [`IrModules`]
//! loads the same way and, in a debug build, rereads a page's module when the
//! build's watch mode rewrites it. Deprecated in
//! 0.2.2, removed in 3.0.0: `render_page` and its Phase 1 fallback,
//! `render_page_with_nonce`, the lenient `load_ir_modules`, [`PageOutput`]'s
//! public fields and `headers()`, and `PageConfig::config_script`.
// Makes README.md's and SECURITY.md's "Zero `unsafe` blocks" a property the
// compiler enforces rather than a claim.
// No `unwrap`, `expect` or `panic!` in the code that ships (DR-12, SR44): a
// render returns its failure. Tests may. The 0.2.1 functions whose signatures
// have no room for an error (`CspNonce::generate`, `assets::asset`, the
// deprecated `assets::load_manifest`) keep their documented panics under a
// scoped `allow`, each with its fallible twin; none is on the render path.
/// Serving content-hashed files out of the embedded `dist` directory.
/// Content-Security-Policy construction and nonce generation.
/// Doctests pinning each deprecation; built only by `cargo test --doc`.
// Documented by its own `//!` docs (the preview frame, DR-14 tier (c)).
/// Typed homes for the page's head: manifest preloads and head links.
/// Loading and version-checking the per-route `.ir` modules at startup.
/// Raw HTML: the one named type for markup written unescaped.
/// The render that returns its failure: `try_render`, `render_browser_shell`.
/// The page response: HTML that never leaves without its policy.
// Documented by its own `//!` docs: an outer `///` line here would merge with
// them and resolve their intra-doc links from the crate root.
/// The HTML page template and the SSR render entry points.
/// Request/response types: page config, manifest, render mode.
/// Re-exported because it appears in [`assets::asset_bytes`]'s signature.
pub use Bytes;
pub use ;
/// Re-exported: [`RenderCtx::with_limits`] takes it.
pub use WalkLimits;
pub use ;
pub use ;
pub use ;
pub use RawHtml;
pub use ;
pub use ;
pub use ;
pub use *;