Minor: explicitly initialize TLS provider in custom binary example to model best-practices.

This commit is contained in:
Sebastian Jeltsch
2026-05-07 09:28:03 +02:00
parent 4abdca6b90
commit 0fa68b2d81
4 changed files with 16 additions and 2 deletions
Generated
+1
View File
@@ -1654,6 +1654,7 @@ dependencies = [
"axum",
"env_logger",
"tokio",
"tokio-rustls",
"trailbase",
]
+7 -2
View File
@@ -694,9 +694,14 @@ pub async fn serve(
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Make sure TLS provider is installed (both for incoming and outgoing traffic, including traffic
// from WASM components).
if tokio_rustls::rustls::crypto::CryptoProvider::get_default().is_none() {
use tokio_rustls::rustls::crypto;
if crypto::CryptoProvider::get_default().is_none() {
info!("No process-wide TLS provider found. Falling back to `aws_lc_rs`.");
let _ = tokio_rustls::rustls::crypto::aws_lc_rs::default_provider().install_default();
if let Err(_provider) = crypto::aws_lc_rs::default_provider().install_default() {
// QUESTION: Should this be a panic or is this still acceptable for users who don't
// need TLS (neither to serve nor for WASM components).
error!("Installing fallback TLS provider failed.");
}
}
let has_tls = tls.is_some();
+1
View File
@@ -8,4 +8,5 @@ publish = false
axum = "^0.8.1"
env_logger = { workspace = true }
tokio = { workspace = true }
tokio-rustls = { workspace = true }
trailbase = { workspace = true }
+7
View File
@@ -31,6 +31,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.default_filter_or("info,trailbase_refinery=warn,tracing::span=warn,swc_ecma_codegen=off"),
);
// Install the process-wide rustls crypto provider. Since rustls 0.23.39 there is no more
// implicit default. W/o this any TLS traffic incoming and outgoing (e.g. via WASM components)
// would panic.
tokio_rustls::rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.expect("Failed to install rustls crypto");
let Server {
state,
main_router,