diff --git a/src/main.rs b/src/main.rs index ac1038a..499d851 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use axum_macros::debug_handler; -use std::{net::SocketAddr, sync::Arc}; +use std::net::SocketAddr; use tower_http::trace::TraceLayer; use crate::ResponseError::{BadRequest, FileNotFound, InternalError}; @@ -7,7 +7,7 @@ use askama::Template; use axum::{ body::{Body, BoxBody}, - extract::Extension, + extract::State, http::{header, HeaderValue, Request, Response, StatusCode}, response::{Html, IntoResponse}, routing::get, @@ -49,6 +49,7 @@ struct Opt { port: u16, } +#[derive(Clone)] struct StaticServerConfig { pub(crate) root_dir: String, } @@ -75,11 +76,10 @@ async fn main() { root_dir = root_dir.trim_end_matches('/').to_string(); } - let app = Router::new() + let app = Router::with_state(StaticServerConfig { root_dir }) .route("/favicon.ico", get(favicon)) .route("/healthz", get(health_check)) .fallback(index_or_content) - .layer(Extension(Arc::new(StaticServerConfig { root_dir }))) .layer(TraceLayer::new_for_http().make_span_with(|request: &Request
| { let ConnectInfo(addr) = request.extensions().get::