forked from 2sys/shoutdotdev
fix uri normalization bug
This commit is contained in:
parent
02166b2d61
commit
e5215613d5
1 changed files with 15 additions and 12 deletions
27
src/cli.rs
27
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::<Request>::into_make_service(router))
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn worker_command(args: &WorkerArgs, state: AppState) -> Result<()> {
|
||||
|
|
Loading…
Add table
Reference in a new issue