mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-18 00:00:15 +02:00
More robust asset paths in examples (#1090)
* More robust asset paths in examples * Update examples/low-level-rustls/src/main.rs Co-authored-by: Jonas Platte <[email protected]> * format Co-authored-by: Jonas Platte <[email protected]>
This commit is contained in:
co-authored by
Jonas Platte
parent
cbb2e8a244
commit
fd70f81c46
@@ -11,7 +11,14 @@ use hyper::server::{
|
||||
conn::{AddrIncoming, Http},
|
||||
};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
use std::{fs::File, io::BufReader, net::SocketAddr, pin::Pin, sync::Arc};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::BufReader,
|
||||
net::SocketAddr,
|
||||
path::{Path, PathBuf},
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
};
|
||||
use tokio::net::TcpListener;
|
||||
use tokio_rustls::{
|
||||
rustls::{Certificate, PrivateKey, ServerConfig},
|
||||
@@ -30,8 +37,12 @@ async fn main() {
|
||||
.init();
|
||||
|
||||
let rustls_config = rustls_server_config(
|
||||
"examples/tls-rustls/self_signed_certs/key.pem",
|
||||
"examples/tls-rustls/self_signed_certs/cert.pem",
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("self_signed_certs")
|
||||
.join("key.pem"),
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("self_signed_certs")
|
||||
.join("cert.pem"),
|
||||
);
|
||||
|
||||
let acceptor = TlsAcceptor::from(rustls_config);
|
||||
@@ -65,7 +76,7 @@ async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String {
|
||||
addr.to_string()
|
||||
}
|
||||
|
||||
fn rustls_server_config(key: &str, cert: &str) -> Arc<ServerConfig> {
|
||||
fn rustls_server_config(key: impl AsRef<Path>, cert: impl AsRef<Path>) -> Arc<ServerConfig> {
|
||||
let mut key_reader = BufReader::new(File::open(key).unwrap());
|
||||
let mut cert_reader = BufReader::new(File::open(cert).unwrap());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user