Skip to content

Commit

Permalink
feat: enable cors
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-eiger committed Oct 12, 2023
1 parent b64b965 commit 7ac3c51
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ data
configs
node_modules
*.json
!schema.json
!schema.json
dist
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions subgraph-radio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ opentelemetry = { version = "0.19.0", features = ["rt-tokio", "trace"] }
tracing-opentelemetry = "0.18.0"
clap = { version = "4.3.1", features = ["derive", "env"] }
confy = "0.5.1"
tower-http = { version = "0.4.3", features = ["cors"] }
http = "0.2.6"

[dev-dependencies]
criterion = { version = "0.4", features = ["async", "async_futures"] }
Expand Down
13 changes: 11 additions & 2 deletions subgraph-radio/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use axum::http::Method;
use axum::{extract::Extension, routing::get, Router};
use axum_server::Handle;
use http::header::HeaderName;
use std::net::SocketAddr;
use std::str::FromStr;

use std::sync::Arc;
use tower_http::cors::{Any, CorsLayer};
use tracing::{debug, info};

use crate::{
Expand Down Expand Up @@ -33,14 +35,21 @@ pub async fn run_server(config: Config, persisted_state: &'static PersistedState

debug!("Setting up HTTP service");

let cors = CorsLayer::new()
.allow_methods(vec![Method::GET, Method::POST])
.allow_origin(Any)
.allow_headers(vec![HeaderName::from_static("content-type")]);

let app = Router::new()
.route("/health", get(health))
.route(
"/api/v1/graphql",
get(graphql_playground).post(graphql_handler),
)
.layer(Extension(schema))
.layer(Extension(context));
.layer(Extension(context))
.layer(cors);

let addr = SocketAddr::from_str(&format!(
"{}:{}",
config.radio_infrastructure().server_host,
Expand Down

0 comments on commit 7ac3c51

Please sign in to comment.