feat: https support

This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-03-09 16:44:42 +03:00
parent aeafc3cf4e
commit ffa21ae8df
3 changed files with 13 additions and 4 deletions

1
.gitignore vendored
View file

@ -4,6 +4,7 @@ debug/
target/ target/
.vscode/ .vscode/
dist/ dist/
certificates/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

View file

@ -7,6 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
axum = "0.7.4" axum = "0.7.4"
axum-server = { version = "0.6.0", features = ["tls-rustls"] }
rand = "0.8.5" rand = "0.8.5"
serde = { version = "1.0.197", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114" serde_json = "1.0.114"

View file

@ -1,5 +1,6 @@
use back::{routing, AppState}; use back::{routing, AppState};
use std::env::{self}; use std::{env, net::SocketAddr};
use axum_server::tls_rustls::RustlsConfig;
fn take_args() -> String{ fn take_args() -> String{
let mut bind_address:String = String::new(); let mut bind_address:String = String::new();
@ -13,11 +14,17 @@ fn take_args() -> String{
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
println!("Hello, world!"); println!("Hello, world!");
let config = RustlsConfig::from_pem_file(
"certificates/fullchain.pem",
"certificates/privkey.pem"
).await.unwrap();
let state = AppState{ let state = AppState{
}; };
let app = routing::routing(axum::extract::State(state)).await; let app = routing::routing(axum::extract::State(state)).await;
let listener = tokio::net::TcpListener::bind(take_args()).await.unwrap(); let addr = SocketAddr::from(take_args().parse::<SocketAddr>().unwrap());
axum::serve(listener, app).await.unwrap(); axum_server::bind_rustls(addr, config)
.serve(app.into_make_service())
.await
.unwrap();
} }