summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs63
1 files changed, 13 insertions, 50 deletions
diff --git a/src/main.rs b/src/main.rs
index 69eed5d..2f3449d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,20 +1,16 @@
mod api;
mod auth;
mod database;
+mod doc;
mod extractors;
-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 {
@@ -37,9 +33,7 @@ async fn main() -> std::io::Result<()> {
let db = Arc::new(db_raw);
/* Get jwt secret from env */
- let jwt_secret = env::var("SECRET")
- .expect("environment variable SECRET is *probably not setted up!!")
- .to_string();
+ let jwt_secret: String = env!("SECRET").to_owned();
/* Application data struct */
let app_state = AppState {
@@ -47,56 +41,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/")
}