1
0
mirror of https://github.com/actix/actix-website synced 2025-02-08 22:36:07 +01:00

29 lines
867 B
Rust
Raw Normal View History

2020-09-12 16:21:54 +01:00
#![allow(dead_code)]
2018-05-23 20:39:15 -07:00
// <ssl>
2020-09-12 16:21:54 +01:00
use actix_web::{get, App, HttpRequest, HttpServer, Responder};
2018-05-23 20:39:15 -07:00
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
2020-09-12 16:21:54 +01:00
#[get("/")]
2019-12-29 03:32:56 +09:00
async fn index(_req: HttpRequest) -> impl Responder {
2018-05-23 20:39:15 -07:00
"Welcome!"
}
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2019-12-29 03:32:56 +09:00
async fn main() -> std::io::Result<()> {
2018-05-23 20:39:15 -07:00
// load ssl keys
// to create a self-signed temporary cert for testing:
// `openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 -subj '/CN=localhost'`
2022-02-26 03:56:24 +00:00
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
2018-05-23 20:39:15 -07:00
builder
.set_private_key_file("key.pem", SslFiletype::PEM)
.unwrap();
builder.set_certificate_chain_file("cert.pem").unwrap();
2020-09-12 16:21:54 +01:00
HttpServer::new(|| App::new().service(index))
.bind_openssl("127.0.0.1:8080", builder)?
2019-06-13 17:10:51 -04:00
.run()
2019-12-29 03:32:56 +09:00
.await
2018-05-23 20:39:15 -07:00
}
// </ssl>