Skip to content

Commit

Permalink
Merge pull request #10 from Wreck-X/master
Browse files Browse the repository at this point in the history
Add cors origin layer.
  • Loading branch information
ivinjabraham authored Oct 3, 2024
2 parents b0fa85a + 9dff096 commit a451d22
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
42 changes: 34 additions & 8 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ tokio = "1.28.2"
hmac = "0.12.1"
sha2 = "0.10.8"
hex = "0.4.3"
tower-http = { version = "0.6.1", features = ["cors"] }
tower = "0.5.1"
chrono-tz = "0.10.0"
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use tokio::time::{ sleep_until, Instant};
use std::time::Duration;
use async_graphql_axum::GraphQL;
use axum::{routing::get, Router};
use tower_http::cors::{Any, CorsLayer};
use chrono::{ Local, NaiveTime};
use chrono_tz::Asia::Kolkata;
use db::member::Member;
Expand Down Expand Up @@ -40,10 +41,16 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool,#[shuttle_runtime::Sec
.finish();

let state = MyState { pool: pool.clone() , secret_key: secret_key.clone()};


let cors = CorsLayer::new()
.allow_origin(Any) // Allow any origin
.allow_methods(tower_http::cors::Any) // Allow any HTTP method
.allow_headers(tower_http::cors::Any);

let router = Router::new()
.route("/", get(graphiql).post_service(GraphQL::new(schema.clone())))
.with_state(state);
.with_state(state)
.layer(cors);
task::spawn(async move {

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

0 comments on commit a451d22

Please sign in to comment.