update tls-rustls example (#494)

This commit is contained in:
Eray Karatay 2021-11-10 17:07:09 +03:00 committed by GitHub
parent 0990e27964
commit 2507463706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 24 deletions

View File

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

View File

@ -4,31 +4,35 @@
//! cargo run -p example-tls-rustls
//! ```
// NOTE: This example is currently broken since axum-server requires `S: Sync`,
// that isn't necessary and will be fixed in a future release
use axum::{routing::get, Router};
use axum_server::tls_rustls::RustlsConfig;
use std::net::SocketAddr;
fn main() {}
#[tokio::main]
async fn main() {
// Set the RUST_LOG, if it hasn't been explicitly defined
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "example_tls_rustls=debug")
}
tracing_subscriber::fmt::init();
// use axum::{handler::get, Router};
let config = RustlsConfig::from_pem_file(
"examples/tls-rustls/self_signed_certs/cert.pem",
"examples/tls-rustls/self_signed_certs/key.pem",
)
.await
.unwrap();
// #[tokio::main]
// async fn main() {
// // Set the RUST_LOG, if it hasn't been explicitly defined
// if std::env::var_os("RUST_LOG").is_none() {
// std::env::set_var("RUST_LOG", "example_tls_rustls=debug")
// }
// tracing_subscriber::fmt::init();
let app = Router::new().route("/", get(handler));
// // let app = Router::new().route("/", get(handler));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum_server::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
// // axum_server::bind_rustls("127.0.0.1:3000")
// // .private_key_file("examples/tls-rustls/self_signed_certs/key.pem")
// // .certificate_file("examples/tls-rustls/self_signed_certs/cert.pem")
// // .serve(app)
// // .await
// // .unwrap();
// }
// async fn handler() -> &'static str {
// "Hello, World!"
// }
async fn handler() -> &'static str {
"Hello, World!"
}