remove CORS support

This commit is contained in:
Emmanuel Garette 2022-10-10 21:17:24 +02:00
parent e846e65cab
commit 927219667d

View file

@ -16,7 +16,6 @@ use std::error::Error;
use rocket::fs::FileServer;
use rocket::http::Method;
use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors};
use empty::*;
use garbage::*;
@ -26,7 +25,6 @@ use get_ip::*;
async fn main() -> Result<(), Box<dyn Error>> {
dotenv().ok();
let cors = setup_cors().await?;
let routes = routes![get_ip::get_ip, get_backend_ip_php];
let garbage_routes = routes![
@ -47,7 +45,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let routes = vec![routes, garbage_routes, empty_routes].concat();
let mut rocketship = rocket::build().attach(cors).mount("/", routes);
let mut rocketship = rocket::build().mount("/", routes);
let asset_path = std::env::current_dir().unwrap().join("assets");
if asset_path.exists() {
@ -60,22 +58,3 @@ async fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}
async fn setup_cors() -> Result<Cors, Box<dyn Error>> {
let allowed_origins = AllowedOrigins::all();
let allowed_methods = vec![Method::Get, Method::Post]
.into_iter()
.map(From::from)
.collect();
let allowed_headers = AllowedHeaders::some(&["Content-Encoding", "Content-Type"]);
let cors = rocket_cors::CorsOptions {
allowed_origins,
allowed_methods,
allowed_headers,
..Default::default()
}
.to_cors()?;
Ok(cors)
}