diff --git a/Cargo.lock b/Cargo.lock
@@ -2073,6 +2073,7 @@ dependencies = [
"tokio",
"tokio-util",
"tower",
+ "tower-http",
"tower-layer",
"tower-service",
"tracing",
diff --git a/Cargo.toml b/Cargo.toml
@@ -34,6 +34,7 @@ tokio-util = { version = "0.7.3", features = ["io"] }
tower = "0.4"
tower-service = "0.3"
tower-layer = "0.3"
+tower-http = { version = "0.3.4", features = ["cors"] }
tracing = "0.1"
tracing-subscriber = "0.3"
unix_mode = "0.1"
diff --git a/src/main.rs b/src/main.rs
@@ -1,8 +1,8 @@
#![deny(clippy::pedantic)]
-use std::{sync::Arc, time::Duration};
use std::net::SocketAddr;
use std::path::PathBuf;
+use std::{sync::Arc, time::Duration};
use askama::Template;
use axum::{
@@ -17,6 +17,7 @@ use axum::{
use bat::assets::HighlightingAssets;
use clap::Parser;
use syntect::html::ClassStyle;
+use tower_http::cors::CorsLayer;
use tower_layer::layer_fn;
use tracing::{info, instrument};
@@ -102,7 +103,8 @@ async fn main() {
.layer(layer_fn(LoggingMiddleware))
.layer(Extension(Arc::new(Git::new(syntax_set))))
.layer(Extension(db))
- .layer(Extension(Arc::new(args.scan_path)));
+ .layer(Extension(Arc::new(args.scan_path)))
+ .layer(CorsLayer::new());
axum::Server::bind(&args.bind_address)
.serve(app.into_make_service_with_connect_info::<std::net::SocketAddr>())
diff --git a/src/methods/repo/mod.rs b/src/methods/repo/mod.rs
@@ -50,7 +50,10 @@ where
bytes::Bytes: From<ReqBody::Data>,
<ReqBody as HttpBody>::Error: std::error::Error + Send + Sync,
{
- let scan_path = request.extensions().get::<Arc<PathBuf>>().expect("scan_path missing");
+ let scan_path = request
+ .extensions()
+ .get::<Arc<PathBuf>>()
+ .expect("scan_path missing");
let mut uri_parts: Vec<&str> = request
.uri()
diff --git a/src/methods/repo/smart_git.rs b/src/methods/repo/smart_git.rs
@@ -63,7 +63,10 @@ pub async fn handle(
let resp = cgi_to_response(&out.stdout)?;
if out.stderr.len() > 0 {
- warn!("Git returned an error: `{}`", String::from_utf8_lossy(&out.stderr));
+ warn!(
+ "Git returned an error: `{}`",
+ String::from_utf8_lossy(&out.stderr)
+ );
}
Ok(resp)
@@ -100,7 +103,11 @@ pub fn cgi_to_response(buffer: &[u8]) -> Result<Response, anyhow::Error> {
);
}
- if let Some(status) = response.headers_mut().remove("Status").filter(|s| s.len() >= 3) {
+ if let Some(status) = response
+ .headers_mut()
+ .remove("Status")
+ .filter(|s| s.len() >= 3)
+ {
let status = &status.as_ref()[..3];
if let Ok(status) = StatusCode::from_bytes(status) {