add admin scope

This commit is contained in:
Manuel Gugger 2021-12-08 18:37:15 +01:00
parent bb545ab742
commit 12796fecfe
3 changed files with 24 additions and 0 deletions

22
src/actix_admin/mod.rs Normal file
View File

@ -0,0 +1,22 @@
use actix_web::{web, guard, HttpRequest, HttpResponse};
async fn index(data: web::Data<super::AppState>) -> &'static str {
"Welcome!"
}
async fn list(data: web::Data<super::AppState>) -> &'static str {
"List!"
}
fn entity_scope() -> actix_web::Scope {
let scope = web::scope("/entity")
.route("/list", web::get().to(list));
scope
}
pub fn admin_scope() -> actix_web::Scope {
let scope = web::scope("/admin")
.route("/", web::get().to(index))
.service(entity_scope());
scope
}

View File

@ -15,6 +15,7 @@ use sea_orm::{{ DatabaseConnection, ConnectOptions }};
mod web_auth; mod web_auth;
mod entity; mod entity;
mod actix_admin;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct AppState { pub struct AppState {
@ -96,6 +97,7 @@ async fn main() {
App::new() App::new()
.app_data(web::Data::new(app_state.clone())) .app_data(web::Data::new(app_state.clone()))
.wrap(CookieSession::signed(&[0; 32]).secure(false)) .wrap(CookieSession::signed(&[0; 32]).secure(false))
.service(actix_admin::admin_scope())
.route("/", web::get().to(index)) .route("/", web::get().to(index))
.route("/login", web::get().to(web_auth::login)) .route("/login", web::get().to(web_auth::login))
.route("/logout", web::get().to(web_auth::logout)) .route("/logout", web::get().to(web_auth::logout))