[#44] Added frontend hosting using feature
							parent
							
								
									e0ac8ddd24
								
							
						
					
					
						commit
						5a95ee5270
					
				| 
						 | 
					@ -4,6 +4,10 @@ version = "1.0.2"
 | 
				
			||||||
authors = ["Jef Roosens <roosensjef@gmail.com>"]
 | 
					authors = ["Jef Roosens <roosensjef@gmail.com>"]
 | 
				
			||||||
edition = "2018"
 | 
					edition = "2018"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[features]
 | 
				
			||||||
 | 
					# Enables hosting of the frontend
 | 
				
			||||||
 | 
					frontend = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[lib]
 | 
					[lib]
 | 
				
			||||||
name = "fej"
 | 
					name = "fej"
 | 
				
			||||||
path = "src/fej/lib.rs"
 | 
					path = "src/fej/lib.rs"
 | 
				
			||||||
| 
						 | 
					@ -41,4 +45,4 @@ diesel_migrations = "1.4.0"
 | 
				
			||||||
[dependencies.rocket_contrib]
 | 
					[dependencies.rocket_contrib]
 | 
				
			||||||
version = "0.4.7"
 | 
					version = "0.4.7"
 | 
				
			||||||
default-features = false
 | 
					default-features = false
 | 
				
			||||||
features = ["json", "diesel_postgres_pool"]
 | 
					features = ["json", "diesel_postgres_pool", "serve"]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,8 @@ COPY --chown=builder:builder migrations/ ./migrations/
 | 
				
			||||||
RUN cargo install \
 | 
					RUN cargo install \
 | 
				
			||||||
    --path . \
 | 
					    --path . \
 | 
				
			||||||
    --root /app/output \
 | 
					    --root /app/output \
 | 
				
			||||||
    --target x86_64-unknown-linux-musl
 | 
					    --target x86_64-unknown-linux-musl \
 | 
				
			||||||
 | 
					    --features frontend
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FROM node:15-alpine3.13 AS frontend-builder
 | 
					FROM node:15-alpine3.13 AS frontend-builder
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,8 @@ use rocket::fairing::{Fairing, Info, Kind};
 | 
				
			||||||
use rocket::http::Header;
 | 
					use rocket::http::Header;
 | 
				
			||||||
use rocket::{Request, Response, Rocket};
 | 
					use rocket::{Request, Response, Rocket};
 | 
				
			||||||
use rocket_contrib::databases::diesel;
 | 
					use rocket_contrib::databases::diesel;
 | 
				
			||||||
 | 
					#[cfg(feature = "frontend")]
 | 
				
			||||||
 | 
					use rocket_contrib::serve::StaticFiles;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct CORS;
 | 
					pub struct CORS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,12 +62,21 @@ fn run_db_migrations(rocket: Rocket) -> Result<Rocket, Rocket> {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn rocket() -> 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(CORS)
 | 
				
			||||||
        .attach(FejDbConn::fairing())
 | 
					        .attach(FejDbConn::fairing())
 | 
				
			||||||
        .attach(AdHoc::on_attach("Database Migrations", run_db_migrations))
 | 
					        .attach(AdHoc::on_attach("Database Migrations", run_db_migrations))
 | 
				
			||||||
        .mount("/ivago", routes::ivago())
 | 
					        .mount("/api/ivago", routes::ivago()) // /api being hardcoded is temporary
 | 
				
			||||||
        .register(catchers![catchers::not_found])
 | 
					        .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() {
 | 
					fn main() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue