Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
httpd: Move `CorsLayer` to `/`
Sebastian Martinez committed 1 year ago
commit 2fef0f5c9c09b4df40f05452351208a09f15f585
parent f456731
3 files changed +13 -22
modified radicle-httpd/src/api.rs
@@ -1,14 +1,10 @@
use std::collections::BTreeMap;
use std::sync::Arc;
-
use std::time::Duration;

-
use axum::http::header::CONTENT_TYPE;
-
use axum::http::Method;
use axum::response::{IntoResponse, Json};
use axum::routing::get;
use axum::Router;
use serde_json::{json, Value};
-
use tower_http::cors::{self, CorsLayer};

use radicle::identity::doc::PayloadId;
use radicle::identity::{DocAt, RepoId};
@@ -122,13 +118,6 @@ pub fn router(ctx: Context) -> Router {
    Router::new()
        .route("/", get(root_handler))
        .merge(v1::router(ctx))
-
        .layer(
-
            CorsLayer::new()
-
                .max_age(Duration::from_secs(86400))
-
                .allow_origin(cors::Any)
-
                .allow_methods([Method::GET])
-
                .allow_headers([CONTENT_TYPE]),
-
        )
}

async fn root_handler() -> impl IntoResponse {
modified radicle-httpd/src/lib.rs
@@ -17,7 +17,11 @@ use axum::http::{Request, Response};
use axum::response::IntoResponse;
use axum::routing::get;
use axum::{middleware, Json, Router};
+
use hyper::header::CONTENT_TYPE;
+
use hyper::Method;
use tokio::net::TcpListener;
+
use tower_http::cors;
+
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
use tracing::Span;

@@ -119,7 +123,14 @@ fn router(options: Options, profile: Profile) -> anyhow::Result<Router> {
        .route("/", get(root_index_handler))
        .merge(git_router)
        .nest("/api", api_router)
-
        .nest("/raw", raw_router);
+
        .nest("/raw", raw_router)
+
        .layer(
+
            CorsLayer::new()
+
                .max_age(Duration::from_secs(86400))
+
                .allow_origin(cors::Any)
+
                .allow_methods([Method::GET])
+
                .allow_headers([CONTENT_TYPE]),
+
        );

    Ok(app)
}
modified radicle-httpd/src/raw.rs
@@ -1,14 +1,12 @@
use std::sync::Arc;
-
use std::time::Duration;

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

use radicle::prelude::RepoId;
use radicle::profile::Profile;
@@ -99,13 +97,6 @@ pub fn router(profile: Arc<Profile>) -> Router {
        .route("/:rid/head/*path", get(file_by_canonical_head_handler))
        .route("/:rid/blobs/:oid", get(file_by_oid_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_by_commit_handler(