Skip to content

Commit 31848a4

Browse files
committed
[Add] CORS permissions
1 parent f969b7b commit 31848a4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ shuttle-axum = "0.53.0"
1111
shuttle-runtime = "0.53.0"
1212
shuttle-secrets = "0.42.0"
1313
tokio = "1.28.2"
14+
tower-http = {version = "0.6.2", features = ["cors"]}

src/main.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use libsql::{ Builder, Database };
33
use std::sync::{ Arc };
44
use std::vec::{ Vec };
55
use tokio::sync::{ RwLock };
6+
use tower_http::cors::{ Any, CorsLayer };
67

78
#[shuttle_runtime::main]
89
async fn main(
@@ -36,6 +37,11 @@ async fn main(
3637
sync_auth: sync_auth
3738
});
3839

40+
let cors = CorsLayer::new()
41+
.allow_methods(Any)
42+
.allow_origin(Any)
43+
.allow_headers(Any);
44+
3945
let router = Router::new()
4046
.route("/api", get(homepage))
4147
.route("/api/mod-list", get(mod_list))
@@ -45,7 +51,8 @@ async fn main(
4551
.route("/api/run-sync", get(redirect_api))
4652
.route("/api/run-sync/", get(redirect_api))
4753
.route("/api/run-sync/{auth}", get(sync_local))
48-
.with_state(app_state);
54+
.with_state(app_state)
55+
.layer(cors);
4956

5057
Ok(router.into())
5158
}

0 commit comments

Comments
 (0)