use axum::{routing::get, Router};
use hyper_serve::tls_rustls::RustlsConfig;
use std::{net::SocketAddr, time::Duration};
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, world!" }));
let config = RustlsConfig::from_pem_file(
"examples/self-signed-certs/cert.pem",
"examples/self-signed-certs/key.pem",
)
.await
.unwrap();
tokio::spawn(reload(config.clone()));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
hyper_serve::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn reload(config: RustlsConfig) {
sleep(Duration::from_secs(20)).await;
println!("reloading rustls configuration");
config
.reload_from_pem_file(
"examples/self-signed-certs/reload/cert.pem",
"examples/self-signed-certs/reload/key.pem",
)
.await
.unwrap();
println!("rustls configuration reloaded");
}