make CORS optional
idk why i forced it Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
12
src/main.rs
12
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::<bool>()
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
fn rocket() -> _ {
|
fn rocket() -> _ {
|
||||||
let cors = rocket_cors::CorsOptions::default().to_cors().unwrap();
|
let cors = rocket_cors::CorsOptions::default().to_cors().unwrap();
|
||||||
@@ -99,7 +106,12 @@ fn rocket() -> _ {
|
|||||||
fs::create_dir_all(env_root_dir()).unwrap();
|
fs::create_dir_all(env_root_dir()).unwrap();
|
||||||
println!("Starting");
|
println!("Starting");
|
||||||
|
|
||||||
|
if env_cors() {
|
||||||
rocket::build()
|
rocket::build()
|
||||||
.attach(cors)
|
.attach(cors)
|
||||||
.mount("/", routes![post_file, get_file, index])
|
.mount("/", routes![post_file, get_file, index])
|
||||||
|
} else {
|
||||||
|
rocket::build()
|
||||||
|
.mount("/", routes![post_file, get_file, index])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user