29 lines
735 B
Rust
29 lines
735 B
Rust
use rocket::fairing::{Fairing, Info, Kind};
|
|
use rocket::http::Header;
|
|
|
|
pub struct Cors;
|
|
|
|
#[rocket::async_trait]
|
|
impl Fairing for Cors {
|
|
fn info(&self) -> Info {
|
|
Info {
|
|
name: "CORS",
|
|
kind: Kind::Response,
|
|
}
|
|
}
|
|
|
|
#[cfg(debug_assertions)]
|
|
async fn on_response<'r>(
|
|
&self,
|
|
_: &'r rocket::Request<'_>,
|
|
response: &mut rocket::Response<'r>,
|
|
) {
|
|
response.set_header(Header::new("Access-Control-Allow-Origin", "*"));
|
|
response.set_header(Header::new(
|
|
"Access-Control-Allow-Methods",
|
|
"POST, GET, DELETE, OPTIONS",
|
|
));
|
|
response.set_header(Header::new("Access-Control-Allow-Headers", "Content-Type"));
|
|
}
|
|
}
|