()
| 19 | |
| 20 | #[actix_web::main] |
| 21 | async fn main() -> io::Result<()> { |
| 22 | env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); |
| 23 | |
| 24 | // build TLS config from files |
| 25 | let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap(); |
| 26 | |
| 27 | // set the encrypted private key |
| 28 | builder |
| 29 | .set_private_key(&load_encrypted_private_key()) |
| 30 | .unwrap(); |
| 31 | |
| 32 | // set the unencrypted private key |
| 33 | // (uncomment if you generate your own key+cert with `mkcert`, and also remove the statement above) |
| 34 | // builder |
| 35 | // .set_private_key_file("key.pem", openssl::ssl::SslFiletype::PEM) |
| 36 | // .unwrap(); |
| 37 | |
| 38 | // set the certificate chain file location |
| 39 | builder.set_certificate_chain_file("cert.pem").unwrap(); |
| 40 | |
| 41 | log::info!("starting HTTPS server at http://localhost:8443"); |
| 42 | |
| 43 | HttpServer::new(|| { |
| 44 | App::new() |
| 45 | // enable logger |
| 46 | .wrap(middleware::Logger::default()) |
| 47 | // simple root handler |
| 48 | .service(web::resource("/").route(web::get().to(index))) |
| 49 | }) |
| 50 | .bind_openssl("127.0.0.1:8443", builder)? |
| 51 | .workers(2) |
| 52 | .run() |
| 53 | .await |
| 54 | } |
| 55 | |
| 56 | fn load_encrypted_private_key() -> PKey<Private> { |
| 57 | let mut file = File::open("key.pem").unwrap(); |
nothing calls this directly
no test coverage detected