pub trait GenerateCertKey {
    // Provided methods
    fn get_cert_key_path() -> Result<(String, String)> { ... }
    fn get_rustls_config<'async_trait>(
        create_if_not_exists: bool
    ) -> Pin<Box<dyn Future<Output = Result<RustlsConfig>> + Send + 'async_trait>>
       where Self: Send + 'async_trait { ... }
    fn generate_cert_key() -> Result<()> { ... }
    fn get_cert_params() -> CertificateParams { ... }
}
Expand description

enable https you can config the cert, private key filepath config generate if target filepath is not exists

use std::net::SocketAddr;
use axum::{Router, routing::get};
use axum_restful::utils::{GenerateCertKey, redirect_http_to_https};

struct GenerateAppCertKey;
impl GenerateCertKey for GenerateAppCertKey {}

// config http,https ports
let http_port = 3000;
let https_port = 3001;
let ip = "0.0.0.0";

// spawn a http service to redirect request to https service
redirect_http_to_https(http_port, https_port, ip).await;

let app: Router = Router::new().route("/hello", get(|| async { "Hello, world!" }));
let tls_config = GenerateAppCertKey::get_rustls_config(true).await.unwrap();
let addr: SocketAddr = format!("{}:{}", ip, https_port).as_str().parse().unwrap();
//axum_server::bind_rustls(addr, tls_config)
//     .serve(app.into_make_service())
 //    .await
  //   .unwrap();
  //  let addr = format!("{}:{}", ip, https_port);
  //  let listener = tokio::net::TcpListener::bind(addr).await.unwrap();

Provided Methods§

source

fn get_cert_key_path() -> Result<(String, String)>

source

fn get_rustls_config<'async_trait>( create_if_not_exists: bool ) -> Pin<Box<dyn Future<Output = Result<RustlsConfig>> + Send + 'async_trait>>
where Self: Send + 'async_trait,

source

fn generate_cert_key() -> Result<()>

source

fn get_cert_params() -> CertificateParams

Object Safety§

This trait is not object safe.

Implementors§