diff --git a/Cargo.toml b/Cargo.toml index 34b35d9..e834413 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,4 @@ shuttle-shared-db = { version = "0.45.0", features = ["postgres", "sqlx"] } sqlx = { version = "0.7.1", features = [ "chrono", "uuid" ] } tokio = "1.28.2" -tower-http = { version = "0.5.0", features = ["fs"] } \ No newline at end of file +tower-http = { version = "0.5.0", features = ["fs", "cors"] } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 60f7d03..85b4739 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use axum::{ routing::{get, post}, Router, }; +use axum::http::Method; use data::MyState; use sqlx::PgPool; use tower_http::services::ServeFile; @@ -48,7 +49,10 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::Shut .route("/add-tea", post(add_tea)) .route("/delete-tea/:id", get(delete_tea_by_id)) //.route("/update-tea", post(update_tea_by_rfid)) // probably already covered by "update_tea_by_id" - .with_state(state); + .with_state(state) + .layer(tower_http::cors::CorsLayer::new() + .allow_methods([Method::GET, Method::POST, Method::DELETE]) + .allow_origin(tower_http::cors::Any)); Ok(router.into()) }