mirror of
https://github.com/zzzzDev4/ias-tea-axum.git
synced 2025-04-21 07:41:21 +02:00
Enable CORS
This commit is contained in:
parent
a8742e0d9d
commit
1dc70a87c8
2 changed files with 6 additions and 2 deletions
|
@ -15,4 +15,4 @@ shuttle-shared-db = { version = "0.45.0", features = ["postgres", "sqlx"] }
|
||||||
sqlx = { version = "0.7.1", features = [ "chrono", "uuid" ] }
|
sqlx = { version = "0.7.1", features = [ "chrono", "uuid" ] }
|
||||||
tokio = "1.28.2"
|
tokio = "1.28.2"
|
||||||
|
|
||||||
tower-http = { version = "0.5.0", features = ["fs"] }
|
tower-http = { version = "0.5.0", features = ["fs", "cors"] }
|
|
@ -6,6 +6,7 @@ use axum::{
|
||||||
routing::{get, post},
|
routing::{get, post},
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
use axum::http::Method;
|
||||||
use data::MyState;
|
use data::MyState;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
use tower_http::services::ServeFile;
|
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("/add-tea", post(add_tea))
|
||||||
.route("/delete-tea/:id", get(delete_tea_by_id))
|
.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"
|
//.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())
|
Ok(router.into())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue