Skip to content

Commit

Permalink
fix(common): add CORS allow origin, headers and methods (#184)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Asseman <alexis@semiotic.ai>
  • Loading branch information
aasseman committed May 22, 2024
1 parent 5b75f00 commit 931ab43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ autometrics = { version = "1.0.1", features = ["prometheus-exporter"] }
tracing = "0.1.40"
tower = "0.4.13"
tower_governor = "0.3.2"
tower-http = { version = "0.5.2", features = ["trace"] }
tower-http = { version = "0.5.2", features = ["trace", "cors"] }
tokio-util = "0.7.10"
bigdecimal = "0.4.2"
serde-inline-default = "0.2.0"
Expand Down
10 changes: 9 additions & 1 deletion common/src/indexer_service/http/indexer_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use alloy_sol_types::eip712_domain;
use anyhow;
use autometrics::prometheus_exporter;
use axum::extract::MatchedPath;
use axum::http::Request;
use axum::http::{Method, Request};
use axum::serve;
use axum::{
async_trait,
Expand All @@ -30,6 +30,8 @@ use thiserror::Error;
use tokio::net::TcpListener;
use tokio::signal;
use tower_governor::{governor::GovernorConfigBuilder, GovernorLayer};
use tower_http::cors;
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
use tracing::{info, info_span};

Expand Down Expand Up @@ -390,6 +392,12 @@ impl IndexerService {
let router = misc_routes
.merge(data_routes)
.merge(options.extra_routes)
.layer(
CorsLayer::new()
.allow_origin(cors::Any)
.allow_headers(cors::Any)
.allow_methods([Method::OPTIONS, Method::POST, Method::GET]),
)
.layer(
TraceLayer::new_for_http()
.make_span_with(|req: &Request<_>| {
Expand Down

0 comments on commit 931ab43

Please sign in to comment.