Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
httpd: Add `CorsLayer` to `/raw` endpoint
Sebastian Martinez committed 3 years ago
commit 27ab41bf3ac2c4d37d0c8de0446a0b593d9eb914
parent 2aff899dc26d3197d53392172dc3b8756255b3f9
1 file changed +10 -1
modified radicle-httpd/src/raw.rs
@@ -1,11 +1,13 @@
use std::sync::Arc;
+
use std::time::Duration;

use axum::extract::State;
-
use axum::http::{header, StatusCode};
+
use axum::http::{header, Method, StatusCode};
use axum::response::IntoResponse;
use axum::routing::get;
use axum::Router;
use hyper::HeaderMap;
+
use tower_http::cors;

use radicle::prelude::Id;
use radicle::profile::Profile;
@@ -93,6 +95,13 @@ pub fn router(profile: Arc<Profile>) -> Router {
    Router::new()
        .route("/:project/:sha/*path", get(file_handler))
        .with_state(profile)
+
        .layer(
+
            cors::CorsLayer::new()
+
                .max_age(Duration::from_secs(86400))
+
                .allow_origin(cors::Any)
+
                .allow_methods([Method::GET])
+
                .allow_headers([header::CONTENT_TYPE]),
+
        )
}

async fn file_handler(