[#44] Added frontend hosting using feature
This commit is contained in:
parent
e0ac8ddd24
commit
5a95ee5270
3 changed files with 21 additions and 5 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Reference in a new issue