webserver_base/lib.rs
1//! Shared logic for Todd Everett Griffin's web servers, as a set of
2//! independently feature-gated **kits**.
3//!
4//! Every kit works on its own — a bot that wants only Telegram notifications
5//! enables `telegram` and compiles neither axum nor Handlebars. Together they
6//! compose into one opinionated web server. Nothing is enabled by default.
7//!
8//! | feature | what it is |
9//! |---|---|
10//! | `templates` | Handlebars registry, the embedded base layout, template data |
11//! | `analytics` | first-party proxies for Plausible and the Sentry browser SDK |
12//! | `sitemap` | sitemap index and url-set generation |
13//! | `feed` | RSS 2.0, Atom 1.0 and JSON Feed for a site's content stream |
14//! | `observability` | Sentry + tracing, initialised in the one order that works |
15//! | `telegram` | outbound Telegram Bot API notifier |
16//! | `webserver` | the server builder, state, bootstrap, static-asset pipeline |
17//! | `pages` | page declarations that produce routes *and* sitemap entries |
18//! | `preset` | Todd Everett Griffin's personal defaults |
19//! | `full` | all of the above |
20//!
21//! # Configuration
22//!
23//! Every kit is constructed manually first; `from_env` is a convenience layered
24//! on top. All environment variables this crate reads are prefixed `WSB_` so
25//! they cannot collide with a project's own.
26
27pub mod env;
28mod environment;
29
30pub use environment::{ENV_ENVIRONMENT, Environment, EnvironmentParseError};
31
32mod traces;
33
34pub use traces::{
35 DEFAULT_BROWSER_TRACES_SAMPLE_RATE, DEFAULT_SERVER_TRACES_SAMPLE_RATE, TracesSampleRate,
36 TracesSampleRateError,
37};
38
39#[cfg(feature = "analytics")]
40pub mod analytics;
41#[cfg(feature = "webserver")]
42pub mod assets;
43#[cfg(feature = "feed")]
44pub mod feed;
45#[cfg(feature = "observability")]
46pub mod observability;
47#[cfg(feature = "sitemap")]
48pub mod sitemap;
49#[cfg(feature = "telegram")]
50pub mod telegram;
51#[cfg(feature = "templates")]
52pub mod templates;
53#[cfg(feature = "webserver")]
54pub mod webserver;
55
56#[cfg(feature = "webserver")]
57pub use webserver::{
58 AppShutdown, Shutdown, WebServer, WebServerError, WebServerState, bootstrap_with_release,
59 bootstrap_with_release_and,
60};
61
62// Every crate whose types appear in this library's API, re-exported so a
63// project integrates through the version this library was built against rather
64// than a second copy that does not unify with it. `serde`'s derive is the
65// exception in practice: its generated code names `::serde`, so a project
66// deriving `Serialize` still depends on it directly.
67pub use serde;
68pub use serde_json;
69pub use tracing;
70
71#[cfg(any(feature = "webserver", feature = "analytics"))]
72pub use axum;
73#[cfg(feature = "webserver")]
74pub use axum_extra;
75#[cfg(any(
76 feature = "templates",
77 feature = "sitemap",
78 feature = "feed",
79 feature = "webserver"
80))]
81pub use chrono;
82#[cfg(feature = "templates")]
83pub use handlebars;
84/// Record your own metrics (`counter!`, `gauge!`, `histogram!`); every server exports them on `/metrics`.
85#[cfg(feature = "webserver")]
86pub use metrics;
87#[cfg(any(feature = "analytics", feature = "telegram"))]
88pub use reqwest;
89#[cfg(feature = "observability")]
90pub use sentry;
91#[cfg(any(feature = "webserver", feature = "analytics", feature = "telegram"))]
92pub use tokio;