Updating tls-rustls example (#2457)

This commit is contained in:
FémLol Stúdió 2023-12-29 01:07:58 +01:00 committed by GitHub
parent 3fda093806
commit 4f010d9b2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 35 deletions

View file

@ -6,7 +6,7 @@ publish = false
[dependencies] [dependencies]
axum = { path = "../../axum" } axum = { path = "../../axum" }
axum-server = { version = "0.3", features = ["tls-rustls"] } axum-server = { version = "0.6", features = ["tls-rustls"] }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
tracing = "0.1" tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] }

View file

@ -27,44 +27,42 @@ struct Ports {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
// Updating this example to hyper 1.0 requires axum_server to update first tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "example_tls_rustls=debug".into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
// tracing_subscriber::registry() let ports = Ports {
// .with( http: 7878,
// tracing_subscriber::EnvFilter::try_from_default_env() https: 3000,
// .unwrap_or_else(|_| "example_tls_rustls=debug".into()), };
// ) // optional: spawn a second server to redirect http requests to this server
// .with(tracing_subscriber::fmt::layer()) tokio::spawn(redirect_http_to_https(ports));
// .init();
// let ports = Ports { // configure certificate and private key used by https
// http: 7878, let config = RustlsConfig::from_pem_file(
// https: 3000, PathBuf::from(env!("CARGO_MANIFEST_DIR"))
// }; .join("self_signed_certs")
// // optional: spawn a second server to redirect http requests to this server .join("cert.pem"),
// tokio::spawn(redirect_http_to_https(ports)); PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("self_signed_certs")
.join("key.pem"),
)
.await
.unwrap();
// // configure certificate and private key used by https let app = Router::new().route("/", get(handler));
// let config = RustlsConfig::from_pem_file(
// PathBuf::from(env!("CARGO_MANIFEST_DIR"))
// .join("self_signed_certs")
// .join("cert.pem"),
// PathBuf::from(env!("CARGO_MANIFEST_DIR"))
// .join("self_signed_certs")
// .join("key.pem"),
// )
// .await
// .unwrap();
// let app = Router::new().route("/", get(handler)); // run https server
let addr = SocketAddr::from(([127, 0, 0, 1], ports.https));
// // run https server tracing::debug!("listening on {}", addr);
// let addr = SocketAddr::from(([127, 0, 0, 1], ports.https)); axum_server::bind_rustls(addr, config)
// tracing::debug!("listening on {}", addr); .serve(app.into_make_service())
// axum_server::bind_rustls(addr, config) .await
.unwrap();
// .await
// .unwrap();
} }
#[allow(dead_code)] #[allow(dead_code)]