[#44] Added frontend hosting using feature

This commit is contained in:
Jef Roosens 2021-04-29 11:34:35 +02:00
parent e0ac8ddd24
commit 5a95ee5270
Signed by: Jef Roosens
GPG key ID: B580B976584B5F30
3 changed files with 21 additions and 5 deletions

View file

@ -20,6 +20,8 @@ use rocket::fairing::{Fairing, Info, Kind};
use rocket::http::Header;
use rocket::{Request, Response, Rocket};
use rocket_contrib::databases::diesel;
#[cfg(feature = "frontend")]
use rocket_contrib::serve::StaticFiles;
pub struct CORS;
@ -60,12 +62,21 @@ fn run_db_migrations(rocket: Rocket) -> Result<Rocket, Rocket> {
}
fn rocket() -> rocket::Rocket {
rocket::ignite()
// This needs to be muted for the frontend feature
let mut rocket = rocket::ignite()
.attach(CORS)
.attach(FejDbConn::fairing())
.attach(AdHoc::on_attach("Database Migrations", run_db_migrations))
.mount("/ivago", routes::ivago())
.register(catchers![catchers::not_found])
.mount("/api/ivago", routes::ivago()) // /api being hardcoded is temporary
.register(catchers![catchers::not_found]);
// TODO make all of this not hard-coded
#[cfg(feature = "frontend")]
{
rocket = rocket.mount("/", StaticFiles::from("/app/dist"));
}
rocket
}
fn main() {