diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 59 |
1 files changed, 12 insertions, 47 deletions
diff --git a/src/main.rs b/src/main.rs index 69eed5d..fab6dd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,19 +2,15 @@ mod api; mod auth; mod database; mod extractors; +mod doc; -use actix_web::{web, App, HttpServer}; +use actix_web::web::Redirect; +use actix_web::{web, App, HttpServer, Responder}; use dotenv::dotenv; use std::env; use std::sync::Arc; -// use utoipa::{ -// openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}, -// Modify, OpenApi, -// }; -// -// use utoipa_swagger_ui::SwaggerUi; -// use database::artist::Artist; +use utoipa_swagger_ui::SwaggerUi; #[derive(Clone)] struct AppState { @@ -47,56 +43,25 @@ async fn main() -> std::io::Result<()> { secret: jwt_secret, }; - // /* utoipa setup */ - // #[derive(OpenApi)] - // #[openapi( - // paths( - // ), - // components( - // schemas( - // Artist - // ) - // ), - // modifiers(&SecurityAddon) - // )] - // struct ApiDoc; - - // struct SecurityAddon; - // impl Modify for SecurityAddon { - // fn modify(&self, openapi : &mut utoipa::openapi::OpenApi) { - // let components = openapi.components.as_mut().unwrap(); - // components.add_security_scheme( - // "bearer_auth", - // SecurityScheme::Http( - // HttpBuilder::new() - // .scheme(HttpAuthScheme::Bearer) - // .bearer_format("JWT") - // .build() - // ), - // ); - // } - // } - - // let openapi = ApiDoc::openapi(); + /* OpenApi */ + let openapi = doc::get_openapi(); /* Server setup */ HttpServer::new(move || { App::new() .app_data(web::Data::new(app_state.clone())) - .route("/", web::get().to(root)) - // .service(SwaggerUi::new("/docs/{_:.*}").url( - // "/docs/openapi.json", - // openapi.clone(), - // )) .service(api::api_scope()) .service(auth::auth_scope()) + .service(SwaggerUi::new("/doc/{_:.*}").url("/docs/openapi.json", openapi.clone())) + .route("/", web::get().to(redirect_to_docs)) + .route("/doc", web::get().to(redirect_to_docs)) }) .bind(("127.0.0.1", 8000))? .run() .await } -/* Main page*/ -async fn root() -> String { - String::from("Server is up and running") +/* Redirection page */ +async fn redirect_to_docs() -> impl Responder { + Redirect::to("/doc/") } |