tenebrous-sheets/src/main.rs

67 lines
1.7 KiB
Rust

#[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 rocket_contrib::serve::StaticFiles;
use rocket_contrib::templates::Template;
use std::env;
pub mod catchers;
pub mod db;
pub mod errors;
pub mod migrator;
pub mod models;
pub mod routes;
#[rocket::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = 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 root_routes: Vec<rocket::Route> = {
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())
//.attach(db::TenebrousDbConn::fairing())
.manage(crate::db::create_pool(db_path).await?)
.mount("/", root_routes)
.mount("/characters", character_routes)
.mount("/api", api_routes)
.mount(
"/scripts",
StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/static/scripts")),
)
.mount(
"/protos",
StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/proto")),
)
.register(catchers)
.launch()
.await
.map_err(|e| e.into())
}