71 lines
1.8 KiB
Rust
71 lines
1.8 KiB
Rust
#[macro_use]
|
|
extern crate rocket;
|
|
|
|
#[macro_use]
|
|
extern crate rocket_contrib;
|
|
|
|
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<dyn std::error::Error>> {
|
|
info!("Running Rocket");
|
|
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())
|
|
.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<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 db = crate::db::create_pool(db_path).await?;
|
|
|
|
make_rocket(db.clone()).await
|
|
}
|