Skip to content

Commit

Permalink
server: Simplify middleware setup
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Mar 13, 2024
1 parent 08142f2 commit 821ca3d
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions server/svix-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};
use tower::ServiceBuilder;
use tower::layer::layer_fn;
use tower_http::cors::{AllowHeaders, Any, CorsLayer};
use tracing_subscriber::layer::SubscriberExt as _;

Expand Down Expand Up @@ -149,21 +149,17 @@ pub async fn run_with_prefix(

let openapi = openapi::postprocess_spec(openapi);
let docs_router = docs::router(openapi);
let app = app
.merge(docs_router)
.layer(
ServiceBuilder::new().layer_fn(move |service| IdempotencyService {
cache: svc_cache.clone(),
service,
}),
)
.layer(
CorsLayer::new()
.allow_origin(Any)
.allow_methods(Any)
.allow_headers(AllowHeaders::mirror_request())
.max_age(Duration::from_secs(600)),
);
let app = app.merge(docs_router).layer((
layer_fn(move |service| IdempotencyService {
cache: svc_cache.clone(),
service,
}),
CorsLayer::new()
.allow_origin(Any)
.allow_methods(Any)
.allow_headers(AllowHeaders::mirror_request())
.max_age(Duration::from_secs(600)),
));

let with_api = cfg.api_enabled;
let with_worker = cfg.worker_enabled;
Expand Down

0 comments on commit 821ca3d

Please sign in to comment.