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

61 lines
1.7 KiB
Rust
Raw Normal View History

2022-08-29 13:53:39 +02:00
mod api;
2022-09-09 13:01:30 +02:00
use std::path::{Path, PathBuf};
use rocket::fs::{FileServer, NamedFile, Options};
2022-09-04 10:08:18 +02:00
use rocket_cors::CorsOptions;
2022-08-29 20:08:16 +02:00
use rocket_db_pools::{mongodb, Database};
2022-08-29 12:03:21 +02:00
use rocket_okapi::{
2022-08-29 13:53:39 +02:00
rapidoc::*,
settings::{OpenApiSettings, UrlObject},
2022-08-29 12:03:21 +02:00
swagger_ui::{make_swagger_ui, SwaggerUIConfig},
};
#[macro_use]
extern crate rocket;
2022-08-29 13:53:39 +02:00
#[derive(Database)]
#[database("party")]
2022-08-29 20:08:16 +02:00
pub struct Db(mongodb::Client);
2022-08-29 13:53:39 +02:00
2022-08-29 12:03:21 +02:00
#[launch]
fn rocket() -> _ {
2022-09-04 10:08:18 +02:00
let cors = CorsOptions::default()
.allowed_origins(rocket_cors::AllOrSome::All)
.to_cors()
.unwrap();
2022-08-29 17:17:31 +02:00
let building_rocket = rocket::build()
2022-08-29 12:03:21 +02:00
.attach(Db::init())
2022-09-04 10:08:18 +02:00
.attach(cors)
2022-09-09 13:01:30 +02:00
.mount("/", FileServer::from("./web/dist").rank(5))
.mount("/users", FileServer::from("./web/dist"))
.mount("/events", FileServer::from("./web/dist"))
2022-08-29 17:17:31 +02:00
.mount(
"/swagger",
make_swagger_ui(&SwaggerUIConfig {
url: "../api/openapi.json".to_owned(),
..Default::default()
}),
)
2022-08-29 13:53:39 +02:00
.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();
2022-08-29 17:17:31 +02:00
api::mount_endpoints(building_rocket, &openapi_settings)
2022-08-29 12:03:21 +02:00
}