pub fn bind_dual_protocol(
address: SocketAddr,
config: RustlsConfig,
) -> Server<DualProtocolAcceptor>
Expand description
Create a Server
that will bind to the provided address, accepting both
HTTP and HTTPS on the same port.
Examples found in repository?
examples/hello-world.rs (line 38)
22async fn main() -> Result<()> {
23 let app = Router::new().route("/", routing::get(|| async { "Hello, world!" }));
24
25 let address = SocketAddr::from(([127, 0, 0, 1], 3000));
26 println!("Listening on {address}.");
27 println!(
28 "Connecting to \"http://{address}\" with any path or query will automatically redirect to \"https://{address}\" with the same path and query."
29 );
30
31 let certificate = rcgen::generate_simple_self_signed([])?;
32 let config = RustlsConfig::from_der(
33 vec![certificate.cert.der().to_vec()],
34 certificate.key_pair.serialize_der(),
35 )
36 .await?;
37
38 axum_server_dual_protocol::bind_dual_protocol(address, config)
39 .set_upgrade(true)
40 .serve(app.into_make_service())
41 .await?;
42
43 Ok(())
44}