forked from Roflin/gamenight
74 lines
2.0 KiB
Rust
74 lines
2.0 KiB
Rust
#[macro_use]
|
|
extern crate rocket;
|
|
#[macro_use]
|
|
extern crate diesel_migrations;
|
|
#[macro_use]
|
|
extern crate diesel;
|
|
|
|
use rocket::{
|
|
fairing::AdHoc,
|
|
figment::{
|
|
providers::{Env, Format, Serialized, Toml},
|
|
Figment, 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]
|
|
async 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>())
|
|
.attach(site::make_cors())
|
|
.mount("/", routes![site::index, site::files])
|
|
.mount(
|
|
"/api",
|
|
routes![
|
|
api::gamenights,
|
|
api::gamenights_unauthorized,
|
|
api::gamenights_post_json,
|
|
api::gamenights_post_json_unauthorized,
|
|
api::register_post_json,
|
|
api::login_post_json,
|
|
api::gamenights_delete_json,
|
|
api::gamenights_delete_json_unauthorized,
|
|
api::games,
|
|
api::games_unauthorized,
|
|
api::get_participants,
|
|
api::get_participants_unauthorized,
|
|
api::post_participants,
|
|
api::post_participants_unauthorized,
|
|
api::delete_participants,
|
|
api::delete_participants_unauthorized,
|
|
],
|
|
);
|
|
|
|
rocket
|
|
}
|