From b6018c2db2f466a75bd375cf3533f1c49367175e Mon Sep 17 00:00:00 2001 From: curly Date: Mon, 15 Jul 2024 18:28:53 -0600 Subject: crap cors --- src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e65c8c5..151ab30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ #[macro_use] extern crate rocket; +use std::collections::HashSet; + use rocket::{http::Status, serde::json::Json, State}; +use rocket_cors::CorsOptions; use serde::{Deserialize, Serialize}; mod uid; @@ -193,8 +196,22 @@ async fn transfer_out(data: Json, db: &State>) -> (Statu #[launch] fn rocket() -> _ { + let cors = CorsOptions{ + allowed_origins: rocket_cors::AllOrSome::All, + allowed_methods: HashSet::from([rocket_cors::Method::from(rocket::http::Method::Post), rocket_cors::Method::from(rocket::http::Method::Get)]), + allow_credentials: false, + allowed_headers: rocket_cors::AllOrSome::All, + expose_headers: HashSet::new(), + max_age: None, + send_wildcard: false, + fairing_route_base: "/cors".to_string(), + fairing_route_rank: 0, + }; + let cors = cors.to_cors().unwrap(); + rocket::build().manage(Mutex::new(DB::load(Config::new()))) .mount("/", routes![index]) .mount("/user", routes![login, get_users_by_name, get_user_authenticated, get_user, new_user, get_all_users, logout, logout_all, get_sessions, delete]) .mount("/transfer", routes![transfer_out]) + .attach(cors) } \ No newline at end of file -- cgit v1.2.3