lan-party-backend/backend/src/main.rs

61 lines
1.7 KiB
Rust

mod api;
use std::path::{Path, PathBuf};
use rocket::fs::{FileServer, NamedFile, Options};
use rocket_cors::CorsOptions;
use rocket_db_pools::{mongodb, Database};
use rocket_okapi::{
rapidoc::*,
settings::{OpenApiSettings, UrlObject},
swagger_ui::{make_swagger_ui, SwaggerUIConfig},
};
#[macro_use]
extern crate rocket;
#[derive(Database)]
#[database("party")]
pub struct Db(mongodb::Client);
#[launch]
fn rocket() -> _ {
let cors = CorsOptions::default()
.allowed_origins(rocket_cors::AllOrSome::All)
.to_cors()
.unwrap();
let building_rocket = rocket::build()
.attach(Db::init())
.attach(cors)
.mount("/", FileServer::from("./web/dist").rank(5))
.mount("/users", FileServer::from("./web/dist"))
.mount("/events", FileServer::from("./web/dist"))
.mount(
"/swagger",
make_swagger_ui(&SwaggerUIConfig {
url: "../api/openapi.json".to_owned(),
..Default::default()
}),
)
.mount(
"/rapidoc/",
make_rapidoc(&RapiDocConfig {
general: GeneralConfig {
spec_urls: vec![UrlObject::new("General", "../api/openapi.json")],
..Default::default()
},
hide_show: HideShowConfig {
allow_spec_url_load: false,
allow_spec_file_load: false,
..Default::default()
},
..Default::default()
}),
);
let openapi_settings = OpenApiSettings::default();
api::mount_endpoints(building_rocket, &openapi_settings)
}