Remove unnecessary axum_server dependency
Some checks failed
Rust / Test (push) Has been cancelled
Rust / Rustfmt (push) Has been cancelled
Rust / Clippy (push) Has been cancelled
Rust / Code coverage (push) Has been cancelled

This commit is contained in:
Alphonse Paix
2025-09-28 14:58:15 +02:00
parent b629a8e2fb
commit c58dfaf647
8 changed files with 30 additions and 203 deletions

View File

@@ -1,4 +1,5 @@
use crate::{configuration::Settings, email_client::EmailClient, routes::require_auth, routes::*};
use anyhow::Context;
use axum::{
Router,
body::Bytes,
@@ -8,11 +9,11 @@ use axum::{
response::{IntoResponse, Response},
routing::{delete, get, post},
};
use axum_server::tls_rustls::RustlsConfig;
use reqwest::{StatusCode, header};
use secrecy::ExposeSecret;
use sqlx::{PgPool, postgres::PgPoolOptions};
use std::{net::TcpListener, sync::Arc, time::Duration};
use std::{sync::Arc, time::Duration};
use tokio::net::TcpListener;
use tower_http::{services::ServeDir, trace::TraceLayer};
use tower_sessions::SessionManagerLayer;
use tower_sessions_redis_store::{
@@ -31,7 +32,6 @@ pub struct AppState {
pub struct Application {
listener: TcpListener,
router: Router,
tls_config: Option<RustlsConfig>,
}
impl Application {
@@ -64,39 +64,15 @@ impl Application {
configuration.application.base_url,
redis_store,
);
let tls_config = if configuration.require_tls {
Some(
RustlsConfig::from_pem_file(
std::env::var("APP_TLS_CERT")
.expect("Failed to read TLS certificate environment variable"),
std::env::var("APP_TLS_KEY")
.expect("Feiled to read TLS private key environment variable"),
)
.await
.expect("Could not create TLS configuration"),
)
} else {
None
};
let listener = TcpListener::bind(address).unwrap();
Ok(Self {
listener,
router,
tls_config,
})
let listener = TcpListener::bind(address)
.await
.context("Could not bind application address.")?;
Ok(Self { listener, router })
}
pub async fn run_until_stopped(self) -> Result<(), std::io::Error> {
tracing::debug!("listening on {}", self.local_addr());
if let Some(tls_config) = self.tls_config {
axum_server::from_tcp_rustls(self.listener, tls_config)
.serve(self.router.into_make_service())
.await
} else {
axum_server::from_tcp(self.listener)
.serve(self.router.into_make_service())
.await
}
axum::serve(self.listener, self.router).await
}
pub fn local_addr(&self) -> String {