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 Mar 4, 2024
1 parent 081d2e8 commit de29bd4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
22 changes: 21 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ tracing-subscriber = { version = "0.3", features = [
] }
tokio = { version = "1.28.1", features = ["full", "rt"] }
chrono = "0.4.33"

tower-http = { version = "0.4.0", features = ["trace", "cors"] }
8 changes: 8 additions & 0 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{

use axum::{extract::Extension, routing::get, Router, Server};
use sqlx::{Pool, Postgres};
use tower_http::cors::{AllowHeaders, AllowMethods, AllowOrigin, CorsLayer};
use tracing::{debug, info};

use crate::{
Expand Down Expand Up @@ -34,12 +35,19 @@ pub async fn run_server(config: Config, db: Pool<Postgres>, _running_program: Ar

debug!("Setting up HTTP service");

// Configure CORS
let cors = CorsLayer::new()
.allow_origin(AllowOrigin::any())
.allow_methods(AllowMethods::any())
.allow_headers(AllowHeaders::any());

let app = Router::new()
.route("/health", get(health))
.route(
"/api/v1/graphql",
get(graphql_playground).post(graphql_handler),
)
.layer(cors)
.layer(Extension(schema))
.layer(Extension(context));
let addr = SocketAddr::from_str(&format!("{}:{}", config.server_host(), port))
Expand Down

0 comments on commit de29bd4

Please sign in to comment.