2021-08-02 23:09:09 +02:00
|
|
|
//! Run with
|
|
|
|
|
//!
|
|
|
|
|
//! ```not_rust
|
2021-08-18 00:49:01 +02:00
|
|
|
//! cargo run -p example-tls-rustls
|
2021-08-02 23:09:09 +02:00
|
|
|
//! ```
|
|
|
|
|
|
2021-08-19 22:37:48 +02:00
|
|
|
use axum::{handler::get, Router};
|
2021-08-01 09:32:47 +03:00
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
2021-08-05 05:25:03 -04:00
|
|
|
// Set the RUST_LOG, if it hasn't been explicitly defined
|
2021-09-12 18:39:43 +03:00
|
|
|
if std::env::var_os("RUST_LOG").is_none() {
|
2021-08-18 00:49:01 +02:00
|
|
|
std::env::set_var("RUST_LOG", "example_tls_rustls=debug")
|
2021-08-05 05:25:03 -04:00
|
|
|
}
|
2021-08-05 20:43:03 +03:00
|
|
|
tracing_subscriber::fmt::init();
|
2021-08-01 22:01:33 +02:00
|
|
|
|
2021-08-19 22:37:48 +02:00
|
|
|
let app = Router::new().route("/", get(handler));
|
2021-08-01 09:32:47 +03:00
|
|
|
|
2021-08-24 10:56:31 +03:00
|
|
|
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();
|
2021-08-01 09:32:47 +03:00
|
|
|
}
|
|
|
|
|
|
2021-08-01 13:48:10 +02:00
|
|
|
async fn handler() -> &'static str {
|
|
|
|
|
"Hello, World!"
|
|
|
|
|
}
|