#![recursion_limit = "256"] #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate diesel; #[macro_use] extern crate diesel_migrations; use rocket::fairing::AdHoc; use rocket::{catchers, routes, Rocket}; use rocket_contrib::database; use rocket_contrib::serve::StaticFiles; #[macro_use] pub mod helpers; pub mod catchers; pub mod graphql; pub mod handlers; pub mod models; pub mod schema; // This macro from `diesel_migrations` defines an `embedded_migrations` module containing a // function named `run`. This allows the example to be run and tested without any outside setup of // the database. embed_migrations!(); #[database("stoptime_db")] pub struct DbConn(diesel::SqliteConnection); /// Runs the database migrations. fn run_db_migrations(rocket: Rocket) -> Result { let conn = DbConn::get_one(&rocket).expect("Failed to get a database connection"); match embedded_migrations::run(&*conn) { Ok(()) => Ok(rocket), Err(e) => { eprintln!("Failed to run database migrations: {:?}", e); Err(rocket) } } } /// Sets up the Rocket application. fn rocket() -> Rocket { let static_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/static"); let static_files = StaticFiles::from(static_dir); rocket::ignite() .attach(DbConn::fairing()) .attach(AdHoc::on_attach("Database Migrations", run_db_migrations)) .manage(graphql::Schema::new(graphql::Query, graphql::Mutation)) .mount( "/", routes![ handlers::index, handlers::graphql_playground, handlers::graphql_get, handlers::graphql_post, ], ) .mount("/static", static_files) .register(catchers![catchers::not_found]) } /// Runs the Rocket application. fn main() { rocket().launch(); }