mod api; use rocket::fs::FileServer; use rocket_cors::CorsOptions; use rocket_db_pools::{mongodb, Database}; use rocket_okapi::{ openapi, rapidoc::*, settings::{OpenApiSettings, UrlObject}, swagger_ui::{make_swagger_ui, SwaggerUIConfig}, }; #[macro_use] extern crate rocket; #[derive(Database)] #[database("party")] pub struct Db(mongodb::Client); #[openapi] #[get("/")] fn index() -> String { format!("Hello, world!") } #[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")) .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) }