mirror of
https://github.com/actix/actix-website
synced 2024-11-25 09:12:42 +01:00
cdbb5dd2b2
closes #202
30 lines
875 B
Rust
30 lines
875 B
Rust
#![allow(dead_code)]
|
|
|
|
// <ssl>
|
|
use actix_web::{get, App, HttpRequest, HttpServer, Responder};
|
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
|
|
|
#[get("/")]
|
|
async fn index(_req: HttpRequest) -> impl Responder {
|
|
"Welcome!"
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
// 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'`
|
|
let mut builder =
|
|
SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
|
|
builder
|
|
.set_private_key_file("key.pem", SslFiletype::PEM)
|
|
.unwrap();
|
|
builder.set_certificate_chain_file("cert.pem").unwrap();
|
|
|
|
HttpServer::new(|| App::new().service(index))
|
|
.bind_openssl("127.0.0.1:8080", builder)?
|
|
.run()
|
|
.await
|
|
}
|
|
// </ssl>
|