|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
use rocket::fairing::{Fairing, Info, Kind}; |
|
|
|
|
use rocket::http::Header; |
|
|
|
|
use rocket::{Request, Response}; |
|
|
|
|
use std::path::PathBuf; |
|
|
|
|
|
|
|
|
|
pub struct CORS { |
|
|
|
|
pub whitelist: Vec<String>, |
|
|
|
@ -22,9 +23,19 @@ impl Fairing for CORS {
|
|
|
|
|
.and_then(|origin| self.whitelist.contains(&origin.to_string()).then(|| origin)) |
|
|
|
|
.and_then(|origin| { |
|
|
|
|
response.set_header(Header::new("Access-Control-Allow-Origin", origin)); |
|
|
|
|
response.set_header(Header::new("Access-Control-Allow-Methods", "POST, GET")); |
|
|
|
|
response.set_header(Header::new( |
|
|
|
|
"Access-Control-Allow-Methods", |
|
|
|
|
"POST, GET, OPTIONS", |
|
|
|
|
)); |
|
|
|
|
response.set_header(Header::new("Access-Control-Allow-Credentials", "true")); |
|
|
|
|
response.set_header(Header::new( |
|
|
|
|
"Access-Control-Allow-Headers", |
|
|
|
|
"User-Token, Content-Type", |
|
|
|
|
)); |
|
|
|
|
Some(()) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[options("/<_path..>")] |
|
|
|
|
pub async fn options_handler(_path: PathBuf) {} |
|
|
|
|