#[macro_use] extern crate rocket; #[macro_use] extern crate rocket_contrib; // Seemingly necessary to get serde::Serialize into scope for Prost // code generation. #[macro_use] extern crate serde_derive; use log::{error, info}; use rocket_contrib::serve::StaticFiles; use rocket_contrib::templates::Template; use std::env; use tonic::transport::Server; pub mod catchers; pub mod db; pub mod errors; pub mod migrator; pub mod models; pub mod routes; async fn make_rocket(database: sqlx::SqlitePool) -> Result<(), Box> { info!("Running Rocket"); let root_routes: Vec = { routes::root::routes() .into_iter() .chain(routes::auth::routes().into_iter()) .collect() }; let api_routes = routes::api::routes(); let character_routes = routes::characters::routes(); let catchers = catchers::catchers(); rocket::ignite() .attach(Template::fairing()) .manage(database) .mount("/", root_routes) .mount("/characters", character_routes) .mount("/api", api_routes) .mount( "/scripts", StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/generated/scripts")), ) .mount( "/protos", StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/proto")), ) .register(catchers) .launch() .await?; Ok(()) } #[rocket::main] async fn main() -> Result<(), Box> { let args: Vec = env::args().collect(); let db_path: &str = match &args[..] { [_, path] => path.as_ref(), [_, _, ..] => panic!("Expected exactly 0 or 1 argument"), _ => "tenebrous.sqlite", }; println!("Using database: {}", db_path); migrator::migrate(db_path).await?; let db = crate::db::create_pool(db_path).await?; make_rocket(db.clone()).await }