httpd: Move CorsLayer to /

This commit is contained in:
Sebastian Martinez
2024-12-05 14:13:56 +01:00
parent f456731f42
commit 2fef0f5c9c
3 changed files with 13 additions and 22 deletions
-11
View File
@@ -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 {
+12 -1
View File
@@ -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)
}
+1 -10
View File
@@ -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(