rustls_server/
rustls_server.rs

1//! Run with `cargo run --all-features --example rustls_server` command.
2//!
3//! To connect through browser, navigate to "https://localhost:3000" url.
4
5use axum::{routing::get, Router};
6use hyper_server::tls_rustls::RustlsConfig;
7use std::net::SocketAddr;
8
9#[tokio::main]
10async fn main() {
11    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
12
13    let config = RustlsConfig::from_pem_file(
14        "examples/self-signed-certs/cert.pem",
15        "examples/self-signed-certs/key.pem",
16    )
17    .await
18    .unwrap();
19
20    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
21    println!("listening on {}", addr);
22    hyper_server::bind_rustls(addr, config)
23        .serve(app.into_make_service())
24        .await
25        .unwrap();
26}