mirror of https://github.com/tokio-rs/axum
update tls-rustls example (#494)
This commit is contained in:
parent
0990e27964
commit
2507463706
|
@ -6,7 +6,7 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = { path = "../../axum" }
|
axum = { path = "../../axum" }
|
||||||
axum-server = { version = "0.2", features = ["tls-rustls"] }
|
axum-server = { version = "0.3", 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"] }
|
||||||
|
|
|
@ -4,31 +4,35 @@
|
||||||
//! cargo run -p example-tls-rustls
|
//! cargo run -p example-tls-rustls
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
// NOTE: This example is currently broken since axum-server requires `S: Sync`,
|
use axum::{routing::get, Router};
|
||||||
// that isn't necessary and will be fixed in a future release
|
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]
|
let app = Router::new().route("/", get(handler));
|
||||||
// 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 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")
|
async fn handler() -> &'static str {
|
||||||
// // .private_key_file("examples/tls-rustls/self_signed_certs/key.pem")
|
"Hello, World!"
|
||||||
// // .certificate_file("examples/tls-rustls/self_signed_certs/cert.pem")
|
}
|
||||||
// // .serve(app)
|
|
||||||
// // .await
|
|
||||||
// // .unwrap();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async fn handler() -> &'static str {
|
|
||||||
// "Hello, World!"
|
|
||||||
// }
|
|
||||||
|
|
Loading…
Reference in New Issue