-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from salvo-rs/db
better website
- Loading branch information
Showing
11 changed files
with
573 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,133 @@ | ||
{{#if need_db_conn}} | ||
{{#if is_web_site}} | ||
use crate::middleware::jwt::jwt_hoop; | ||
{{/if}} | ||
use salvo::{ | ||
prelude::{CatchPanic, Logger, OpenApi, SwaggerUi}, | ||
Router, | ||
}; | ||
|
||
use self::{ | ||
demo::hello, | ||
{{#if need_db_conn}} | ||
{{#if is_web_site}} | ||
user::{ | ||
delete_user,login_page, post_add_user, post_login, post_update_user, | ||
delete_user, get_users, login_page, post_add_user, post_login, put_update_user, | ||
user_list_page, | ||
}, | ||
{{else}} | ||
}; | ||
pub mod demo; | ||
pub mod user; | ||
|
||
pub fn router() -> Router { | ||
let mut no_auth_routers = vec![ | ||
Router::with_path("login").get(login_page), | ||
Router::with_path("/api/login").post(post_login), | ||
]; | ||
|
||
let mut need_auth_routers = vec![ | ||
Router::with_path("users") | ||
.get(user_list_page), | ||
Router::with_path("/api/users").get(get_users) | ||
.post(post_add_user) | ||
.push( | ||
Router::with_path("<id>") | ||
.put(put_update_user) | ||
.delete(delete_user), | ||
), | ||
]; | ||
let router = Router::new() | ||
.hoop(Logger::new()) | ||
.hoop(CatchPanic::new()) | ||
.get(hello) | ||
.append(&mut no_auth_routers) | ||
.push( | ||
Router::new() | ||
.append(&mut need_auth_routers) | ||
.hoop(jwt_hoop()), | ||
); | ||
let doc = OpenApi::new("salvo web api", "0.0.1").merge_router(&router); | ||
router | ||
.push(doc.into_router("/api-doc/openapi.json")) | ||
.push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui")) | ||
} | ||
{{else}} | ||
use crate::middleware::jwt::jwt_hoop; | ||
use salvo::{ | ||
prelude::{CatchPanic, Logger, OpenApi, SwaggerUi}, | ||
Router, | ||
}; | ||
|
||
use self::{ | ||
demo::hello, | ||
user::{ | ||
delete_user, get_users, post_add_user, post_login, post_update_user, | ||
delete_user, get_users, post_add_user, post_login, put_update_user, | ||
}, | ||
{{/if}} | ||
{{/if}} | ||
}; | ||
pub mod demo; | ||
{{#if need_db_conn}} | ||
pub mod user; | ||
{{/if}} | ||
|
||
pub fn router() -> Router { | ||
let mut no_auth_routers = vec![ | ||
Router::with_path("/api/login").post(post_login), | ||
]; | ||
|
||
let mut need_auth_routers = vec![ | ||
Router::with_path("/api/users").get(get_users) | ||
.post(post_add_user) | ||
.push( | ||
Router::with_path("<id>") | ||
.put(put_update_user) | ||
.delete(delete_user), | ||
), | ||
]; | ||
let router = Router::new() | ||
.hoop(Logger::new()) | ||
.hoop(CatchPanic::new()) | ||
{{#if need_db_conn}} | ||
.get(hello) | ||
{{#if is_web_site}} | ||
.push(Router::with_path("login").get(login_page).post(post_login)) | ||
{{else}} | ||
.push(Router::with_path("login").post(post_login)) | ||
{{/if}} | ||
.push(user_router().hoop(jwt_hoop())); | ||
{{else}} | ||
.append(&mut no_auth_routers) | ||
.push( | ||
Router::new() | ||
.append(&mut need_auth_routers) | ||
.hoop(jwt_hoop()), | ||
); | ||
let doc = OpenApi::new("salvo web api", "0.0.1").merge_router(&router); | ||
router | ||
.push(doc.into_router("/api-doc/openapi.json")) | ||
.push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui")) | ||
} | ||
{{/if}} | ||
{{else}} | ||
{{#if is_web_site}} | ||
use salvo::{ | ||
prelude::{CatchPanic, Logger, OpenApi, SwaggerUi}, | ||
Router, | ||
}; | ||
use self::demo::hello; | ||
pub mod demo; | ||
pub fn router() -> Router { | ||
let router = Router::new() | ||
.hoop(Logger::new()) | ||
.hoop(CatchPanic::new()) | ||
.get(hello); | ||
{{/if}} | ||
let doc = OpenApi::new("salvo web api", "0.0.1").merge_router(&router); | ||
router | ||
.push(doc.into_router("/api-doc/openapi.json")) | ||
.push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui")) | ||
} | ||
{{#if need_db_conn}} | ||
pub fn user_router() -> Router { | ||
Router::with_path("user") | ||
.post(post_add_user) | ||
.put(post_update_user) | ||
.delete(delete_user) | ||
{{#if is_web_site}} | ||
.get(user_list_page) | ||
{{else}} | ||
.get(get_users) | ||
{{/if}} | ||
{{else}} | ||
use salvo::{ | ||
prelude::{CatchPanic, Logger, OpenApi, SwaggerUi}, | ||
Router, | ||
}; | ||
use self::demo::hello; | ||
pub mod demo; | ||
pub fn router() -> Router { | ||
let router = Router::new() | ||
.hoop(Logger::new()) | ||
.hoop(CatchPanic::new()) | ||
.get(hello); | ||
let doc = OpenApi::new("salvo web api", "0.0.1").merge_router(&router); | ||
router | ||
.push(doc.into_router("/api-doc/openapi.json")) | ||
.push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui")) | ||
} | ||
{{/if}} | ||
{{/if}} |
Oops, something went wrong.