use library::Libary; mod cache; mod library; mod route; use library::user::{User, UserRole}; use rocket::routes; use rocket::{http::Method, launch}; #[launch] async fn rocket() -> _ { env_logger::init(); let cors = rocket_cors::CorsOptions { allowed_origins: rocket_cors::AllowedOrigins::all(), allowed_methods: vec![Method::Get, Method::Post, Method::Options] .into_iter() .map(From::from) .collect(), allowed_headers: rocket_cors::AllowedHeaders::all(), allow_credentials: true, ..Default::default() } .to_cors() .expect("error creating CORS options"); let lib = Libary::new("./media".into()).await; lib.rescan().await; User::create("admin", "admin", UserRole::Admin).await; let cache = cache::RouteCache::new(); rocket::build() .mount( "/", routes![ route::index_redir, route::manifest_redir, route::artist::artists_route, route::artist::artist_route, route::artist::artist_image_route, route::album::albums_route, route::album::album_route, route::track::track_route, route::track::track_audio_route, route::album::album_cover_route, route::user::login_route, route::user::passwd_route, route::user::user_create_route, route::track::track_audio_opus128_route ], ) .manage(lib) .manage(cache) .attach(cors) }