Skip to content

Commit a451d22

Browse files
authored
Merge pull request #10 from Wreck-X/master
Add cors origin layer.
2 parents b0fa85a + 9dff096 commit a451d22

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

Cargo.lock

Lines changed: 34 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ tokio = "1.28.2"
1717
hmac = "0.12.1"
1818
sha2 = "0.10.8"
1919
hex = "0.4.3"
20+
tower-http = { version = "0.6.1", features = ["cors"] }
21+
tower = "0.5.1"
2022
chrono-tz = "0.10.0"

src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use tokio::time::{ sleep_until, Instant};
55
use std::time::Duration;
66
use async_graphql_axum::GraphQL;
77
use axum::{routing::get, Router};
8+
use tower_http::cors::{Any, CorsLayer};
89
use chrono::{ Local, NaiveTime};
910
use chrono_tz::Asia::Kolkata;
1011
use db::member::Member;
@@ -40,10 +41,16 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool,#[shuttle_runtime::Sec
4041
.finish();
4142

4243
let state = MyState { pool: pool.clone() , secret_key: secret_key.clone()};
43-
44+
45+
let cors = CorsLayer::new()
46+
.allow_origin(Any) // Allow any origin
47+
.allow_methods(tower_http::cors::Any) // Allow any HTTP method
48+
.allow_headers(tower_http::cors::Any);
49+
4450
let router = Router::new()
4551
.route("/", get(graphiql).post_service(GraphQL::new(schema.clone())))
46-
.with_state(state);
52+
.with_state(state)
53+
.layer(cors);
4754
task::spawn(async move {
4855

4956
schedule_task_at_midnight(pool.clone()).await; // Call the function after 10 seconds

0 commit comments

Comments
 (0)