2023-08-25 16:52:03 +00:00
|
|
|
use rocket::fairing::{Fairing, Info, Kind};
|
|
|
|
use rocket::http::Header;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
mod controller;
|
|
|
|
mod model;
|
|
|
|
|
|
|
|
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, OPTIONS",
|
|
|
|
));
|
|
|
|
response.set_header(Header::new("Access-Control-Allow-Headers", "Content-Type"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[launch]
|
|
|
|
fn rocket() -> _ {
|
|
|
|
rocket::build()
|
|
|
|
.attach(Cors {})
|
2023-08-25 22:31:46 +00:00
|
|
|
.mount("/api", routes![
|
|
|
|
controller::person::get_by_dni,
|
|
|
|
controller::course::get_all,
|
|
|
|
])
|
2023-08-25 16:52:03 +00:00
|
|
|
}
|