pub fn bind_rustls(
addr: SocketAddr,
config: RustlsConfig,
) -> Server<RustlsAcceptor>
Available on crate feature
tls-rustls
only.Expand description
Create a tls server that will bind to provided address.
Examples found in repository?
examples/http_and_https.rs (line 48)
36async fn https_server() {
37 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
38
39 let config = RustlsConfig::from_pem_file(
40 "examples/self-signed-certs/cert.pem",
41 "examples/self-signed-certs/key.pem",
42 )
43 .await
44 .unwrap();
45
46 let addr = SocketAddr::from(([127, 0, 0, 1], 3443));
47 println!("https listening on {}", addr);
48 axum_server::bind_rustls(addr, config)
49 .serve(app.into_make_service())
50 .await
51 .unwrap();
52}
More examples
examples/rustls_reload.rs (line 30)
15async fn main() {
16 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
17
18 let config = RustlsConfig::from_pem_file(
19 "examples/self-signed-certs/cert.pem",
20 "examples/self-signed-certs/key.pem",
21 )
22 .await
23 .unwrap();
24
25 // Spawn a task to reload tls.
26 tokio::spawn(reload(config.clone()));
27
28 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
29 println!("listening on {}", addr);
30 axum_server::bind_rustls(addr, config)
31 .serve(app.into_make_service())
32 .await
33 .unwrap();
34}