Files
axum/examples/tls-rustls/src/main.rs
T

39 lines
959 B
Rust
Raw Normal View History

2021-08-02 23:09:09 +02:00
//! Run with
//!
//! ```not_rust
//! cargo run -p example-tls-rustls
2021-08-02 23:09:09 +02:00
//! ```
2021-11-10 17:07:09 +03:00
use axum::{routing::get, Router};
use axum_server::tls_rustls::RustlsConfig;
use std::net::SocketAddr;
2021-08-01 09:32:47 +03:00
2021-11-10 17:07:09 +03:00
#[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();
2021-11-10 17:07:09 +03:00
let config = RustlsConfig::from_pem_file(
"examples/tls-rustls/self_signed_certs/cert.pem",
"examples/tls-rustls/self_signed_certs/key.pem",
)
.await
.unwrap();
2021-08-01 09:32:47 +03:00
2021-11-10 17:07:09 +03:00
let app = Router::new().route("/", get(handler));
2021-08-01 09:32:47 +03:00
2021-11-10 17:07:09 +03:00
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();
}
2021-11-10 17:07:09 +03:00
async fn handler() -> &'static str {
"Hello, World!"
}