[#24] Added db connection to server
parent
5746d29556
commit
3a490fca35
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rocket_contrib;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
@ -14,6 +16,7 @@ mod routes;
|
||||||
use rocket::fairing::{Fairing, Info, Kind};
|
use rocket::fairing::{Fairing, Info, Kind};
|
||||||
use rocket::http::Header;
|
use rocket::http::Header;
|
||||||
use rocket::{Request, Response};
|
use rocket::{Request, Response};
|
||||||
|
use rocket_contrib::databases::diesel;
|
||||||
|
|
||||||
pub struct CORS;
|
pub struct CORS;
|
||||||
|
|
||||||
|
@ -36,9 +39,14 @@ impl Fairing for CORS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This defines a connection to the database
|
||||||
|
#[database("postgres_fej")]
|
||||||
|
struct FejDbConn(diesel::PgConnection);
|
||||||
|
|
||||||
fn rocket() -> rocket::Rocket {
|
fn rocket() -> rocket::Rocket {
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.attach(CORS)
|
.attach(CORS)
|
||||||
|
.attach(FejDbConn::fairing())
|
||||||
.mount("/ivago", routes::ivago())
|
.mount("/ivago", routes::ivago())
|
||||||
.register(catchers![catchers::not_found])
|
.register(catchers![catchers::not_found])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue