From ddcc8b59243bc5fcb42e8907bf18df37ac32021b Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Wed, 23 Nov 2022 07:48:41 +0530 Subject: [PATCH] make CORS optional idk why i forced it Signed-off-by: Amneesh Singh --- src/main.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 097882d..dd868b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,13 @@ fn env_user_url() -> String { )) } +fn env_cors() -> bool { + env::var("USE_CORS") + .unwrap_or("false".to_string()) + .parse::() + .unwrap_or(false) +} + #[launch] fn rocket() -> _ { let cors = rocket_cors::CorsOptions::default().to_cors().unwrap(); @@ -99,7 +106,12 @@ fn rocket() -> _ { fs::create_dir_all(env_root_dir()).unwrap(); println!("Starting"); - rocket::build() - .attach(cors) - .mount("/", routes![post_file, get_file, index]) + if env_cors() { + rocket::build() + .attach(cors) + .mount("/", routes![post_file, get_file, index]) + } else { + rocket::build() + .mount("/", routes![post_file, get_file, index]) + } }