45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
#![feature(proc_macro_hygiene, decl_macro)]
|
|
|
|
#[macro_use]
|
|
extern crate rocket;
|
|
mod catchers;
|
|
mod routes;
|
|
|
|
// 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", routes::ivago())
|
|
.register(catchers![catchers::not_found])
|
|
}
|
|
|
|
fn main() {
|
|
rocket().launch();
|
|
}
|