#[macro_use] extern crate rocket; #[macro_use] extern crate diesel_migrations; #[macro_use] extern crate diesel; use rocket::{fairing::AdHoc, figment::{Figment, providers::{Serialized, Toml, Env, Format}, Profile}}; use rocket_dyn_templates::Template; use serde::{Deserialize, Serialize}; mod api; pub mod schema; mod site; #[derive(Debug, Deserialize, Serialize)] pub struct AppConfig { jwt_secret: String } impl Default for AppConfig { fn default() -> AppConfig { AppConfig { jwt_secret: String::from("secret") } } } #[launch] fn rocket() -> _ { let figment = Figment::from(rocket::Config::default()) .merge(Serialized::defaults(AppConfig::default())) .merge(Toml::file("App.toml").nested()) .merge(Env::prefixed("APP_").global()) .select(Profile::from_env_or("APP_PROFILE", "default")); let rocket = rocket::custom(figment) .attach(schema::DbConn::fairing()) .attach(Template::fairing()) .attach(AdHoc::on_ignite("Run Migrations", schema::run_migrations)) .attach(AdHoc::config::()) .mount("/", routes![site::index, site::gamenights, site::add_game_night, site::register]) .mount("/api", routes![ api::gamenights, api::gamenight_post_json, api::register_post_json, api::login_post_json ]); rocket }