mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-05-19 07:49:57 -05:00
Minor: explicitly initialize TLS provider in custom binary example to model best-practices.
This commit is contained in:
Generated
+1
@@ -1654,6 +1654,7 @@ dependencies = [
|
||||
"axum",
|
||||
"env_logger",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"trailbase",
|
||||
]
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -8,4 +8,5 @@ publish = false
|
||||
axum = "^0.8.1"
|
||||
env_logger = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tokio-rustls = { workspace = true }
|
||||
trailbase = { workspace = true }
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user