forked from Roflin/gamenight
47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
|
#[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::<AppConfig>())
|
||
|
.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
|
||
|
}
|