diff --git a/src/cli.rs b/src/cli.rs index db5309f..a5a3bd3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,7 +1,9 @@ use anyhow::Result; use axum::{ + extract::Request, http::{header::CONTENT_SECURITY_POLICY, HeaderValue}, middleware::map_request, + ServiceExt, }; use chrono::{TimeDelta, Utc}; use clap::{Parser, Subcommand}; @@ -41,17 +43,16 @@ pub enum Commands { } pub async fn serve_command(state: AppState) -> Result<()> { - let router = new_router(state.clone()).layer( - ServiceBuilder::new() - .layer(map_request(lowercase_uri_path)) - .layer(TraceLayer::new_for_http()) - .layer(CompressionLayer::new()) - .layer(NormalizePathLayer::trim_trailing_slash()) - .layer(SetResponseHeaderLayer::if_not_present( - CONTENT_SECURITY_POLICY, - HeaderValue::from_static("frame-ancestors 'none'"), - )), - ); + let router = ServiceBuilder::new() + .layer(map_request(lowercase_uri_path)) + .layer(TraceLayer::new_for_http()) + .layer(CompressionLayer::new()) + .layer(SetResponseHeaderLayer::if_not_present( + CONTENT_SECURITY_POLICY, + HeaderValue::from_static("frame-ancestors 'none'"), + )) + .layer(NormalizePathLayer::trim_trailing_slash()) + .service(new_router(state.clone())); let listener = tokio::net::TcpListener::bind((state.settings.host.clone(), state.settings.port)) @@ -64,7 +65,9 @@ pub async fn serve_command(state: AppState) -> Result<()> { state.settings.base_path ); - axum::serve(listener, router).await.map_err(Into::into) + axum::serve(listener, ServiceExt::::into_make_service(router)) + .await + .map_err(Into::into) } pub async fn worker_command(args: &WorkerArgs, state: AppState) -> Result<()> {