Added temporary CORS fix

master
Jef Roosens 2021-04-14 22:00:56 +02:00
parent 9ee542197d
commit 87f2659b48
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
1 changed files with 28 additions and 0 deletions

View File

@ -3,8 +3,36 @@ extern crate rocket;
use fej_lib::{catchers, ivago};
// Very temporary solution for CORS
// https://stackoverflow.com/questions/62412361/how-to-set-up-cors-or-options-for-rocket-rs
use rocket::fairing::{Fairing, Info, Kind};
use rocket::http::Header;
use rocket::{Request, Response};
pub struct CORS;
impl Fairing for CORS {
fn info(&self) -> Info {
Info {
name: "Add CORS headers to responses",
kind: Kind::Response,
}
}
fn on_response(&self, _: &Request, response: &mut Response) {
response.set_header(Header::new("Access-Control-Allow-Origin", "*"));
response.set_header(Header::new(
"Access-Control-Allow-Methods",
"POST, GET, PATCH, OPTIONS",
));
response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
response.set_header(Header::new("Access-Control-Allow-Credentials", "true"));
}
}
fn rocket() -> rocket::Rocket {
rocket::ignite()
.attach(CORS)
.mount("/ivago", ivago::routes())
.register(catchers![catchers::not_found])
}