Added temporary CORS fix
parent
9ee542197d
commit
87f2659b48
28
src/main.rs
28
src/main.rs
|
@ -3,8 +3,36 @@ extern crate rocket;
|
||||||
|
|
||||||
use fej_lib::{catchers, ivago};
|
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 {
|
fn rocket() -> rocket::Rocket {
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
|
.attach(CORS)
|
||||||
.mount("/ivago", ivago::routes())
|
.mount("/ivago", ivago::routes())
|
||||||
.register(catchers![catchers::not_found])
|
.register(catchers![catchers::not_found])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue