1
0
mirror of https://github.com/actix/actix-website synced 2024-11-25 17:22:42 +01:00
actix-website/examples/server/src/ssl.rs

27 lines
674 B
Rust
Raw Normal View History

2018-05-24 05:39:15 +02:00
// <ssl>
2019-06-13 23:10:51 +02:00
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
2018-05-24 05:39:15 +02:00
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
2019-06-13 23:10:51 +02:00
fn index(_req: HttpRequest) -> impl Responder {
2018-05-24 05:39:15 +02:00
"Welcome!"
}
2019-06-13 23:10:51 +02:00
pub fn main() {
2018-05-24 05:39:15 +02:00
// load ssl keys
2019-06-13 23:10:51 +02:00
let mut builder =
SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
2018-05-24 05:39:15 +02:00
builder
.set_private_key_file("key.pem", SslFiletype::PEM)
.unwrap();
builder.set_certificate_chain_file("cert.pem").unwrap();
2019-06-13 23:10:51 +02:00
HttpServer::new(|| App::new().route("/", web::get().to(index)))
.bind_ssl("127.0.0.1:8088", builder)
2018-05-24 05:39:15 +02:00
.unwrap()
2019-06-13 23:10:51 +02:00
.run()
.unwrap();
2018-05-24 05:39:15 +02:00
}
// </ssl>
2019-06-13 23:10:51 +02:00
//
// sssl rust-tls