fej/src/bin/server/main.rs

45 lines
1.2 KiB
Rust
Raw Normal View History

#![feature(proc_macro_hygiene, decl_macro)]
2021-04-02 21:20:36 +02:00
#[macro_use]
extern crate rocket;
mod catchers;
mod routes;
2021-03-06 00:25:40 +01:00
2021-04-14 22:00:56 +02:00
// 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"));
}
}
2021-03-06 00:25:40 +01:00
fn rocket() -> rocket::Rocket {
rocket::ignite()
2021-04-14 22:00:56 +02:00
.attach(CORS)
.mount("/ivago", routes::ivago())
.register(catchers![catchers::not_found])
2021-03-06 00:25:40 +01:00
}
2021-03-05 18:55:18 +01:00
2021-03-05 18:39:49 +01:00
fn main() {
2021-03-06 00:25:40 +01:00
rocket().launch();
2021-03-05 18:39:49 +01:00
}