[#24] Added db connection to server

master^2
Jef Roosens 2021-04-17 10:52:55 +02:00
parent 5746d29556
commit 3a490fca35
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
1 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,8 @@
#[macro_use]
extern crate rocket;
#[macro_use]
extern crate rocket_contrib;
#[cfg(test)]
mod tests;
@ -14,6 +16,7 @@ mod routes;
use rocket::fairing::{Fairing, Info, Kind};
use rocket::http::Header;
use rocket::{Request, Response};
use rocket_contrib::databases::diesel;
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 {
rocket::ignite()
.attach(CORS)
.attach(FejDbConn::fairing())
.mount("/ivago", routes::ivago())
.register(catchers![catchers::not_found])
}