2020-12-01 21:32:16 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket_contrib;
|
|
|
|
|
2020-12-08 08:47:34 +00:00
|
|
|
// Seemingly necessary to get serde::Serialize into scope for Prost
|
|
|
|
// code generation.
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
|
2021-01-03 21:24:52 +00:00
|
|
|
use log::{error, info};
|
2020-12-09 22:21:31 +00:00
|
|
|
use rocket_contrib::serve::StaticFiles;
|
2020-12-01 21:32:16 +00:00
|
|
|
use rocket_contrib::templates::Template;
|
2020-12-31 14:02:14 +00:00
|
|
|
use std::env;
|
2021-01-03 21:24:52 +00:00
|
|
|
use tonic::transport::Server;
|
2020-12-01 21:32:16 +00:00
|
|
|
|
|
|
|
pub mod catchers;
|
|
|
|
pub mod db;
|
|
|
|
pub mod errors;
|
2020-12-30 16:14:04 +00:00
|
|
|
pub mod migrator;
|
2020-12-01 21:32:16 +00:00
|
|
|
pub mod models;
|
|
|
|
pub mod routes;
|
|
|
|
|
2021-01-02 21:26:09 +00:00
|
|
|
async fn make_rocket(database: sqlx::SqlitePool) -> Result<(), Box<dyn std::error::Error>> {
|
2021-01-03 21:24:52 +00:00
|
|
|
info!("Running Rocket");
|
2020-12-01 21:32:16 +00:00
|
|
|
let root_routes: Vec<rocket::Route> = {
|
|
|
|
routes::root::routes()
|
|
|
|
.into_iter()
|
|
|
|
.chain(routes::auth::routes().into_iter())
|
|
|
|
.collect()
|
|
|
|
};
|
|
|
|
|
2020-12-27 21:03:10 +00:00
|
|
|
let api_routes = routes::api::routes();
|
2020-12-01 21:32:16 +00:00
|
|
|
let character_routes = routes::characters::routes();
|
|
|
|
let catchers = catchers::catchers();
|
|
|
|
|
|
|
|
rocket::ignite()
|
|
|
|
.attach(Template::fairing())
|
2021-01-02 21:26:09 +00:00
|
|
|
.manage(database)
|
2020-12-01 21:32:16 +00:00
|
|
|
.mount("/", root_routes)
|
|
|
|
.mount("/characters", character_routes)
|
2020-12-27 21:03:10 +00:00
|
|
|
.mount("/api", api_routes)
|
|
|
|
.mount(
|
|
|
|
"/scripts",
|
2021-01-09 13:03:07 +00:00
|
|
|
StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/generated/scripts")),
|
2020-12-27 21:03:10 +00:00
|
|
|
)
|
2020-12-09 22:21:31 +00:00
|
|
|
.mount(
|
|
|
|
"/protos",
|
|
|
|
StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/proto")),
|
|
|
|
)
|
2020-12-01 21:32:16 +00:00
|
|
|
.register(catchers)
|
2020-12-13 13:57:50 +00:00
|
|
|
.launch()
|
2021-01-03 13:36:48 +00:00
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
2020-12-01 21:32:16 +00:00
|
|
|
}
|
2021-01-02 21:26:09 +00:00
|
|
|
|
|
|
|
#[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?;
|
|
|
|
|
2021-01-05 21:19:47 +00:00
|
|
|
make_rocket(db.clone()).await
|
2021-01-02 21:26:09 +00:00
|
|
|
}
|