aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
1 files changed, 17 insertions, 0 deletions
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<TransferForm>, db: &State<Mutex<DB>>) -> (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