Skip to content

Commit

Permalink
反问路径改配置
Browse files Browse the repository at this point in the history
  • Loading branch information
shanliu committed Jul 23, 2023
1 parent eb82e2a commit 7f4c560
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions server/examples/lsys-actix-web/config/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ rbac_cache=true

#静态文件目录
ui_dir="../../../ui/public/"
#静态文件访问路径,默认:/ui/
#ui_path="/ui/"
#超级管理员id
root_user_id=[1,17]

Expand Down
33 changes: 22 additions & 11 deletions server/examples/lsys-actix-web/src/handler/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,35 @@ pub(crate) fn router_ui<T>(app: App<T>, app_dao: &Arc<WebDao>) -> App<T>
where
T: ServiceFactory<ServiceRequest, Config = (), Error = Error, InitError = ()>,
{
if let Ok(ui_dir) = app_dao.app_core.config.get_string("ui_dir") {
let mut ui_path = PathBuf::from_str(&ui_dir);
if let Ok(ref ui_buf) = ui_path {
let ui_path = app_dao
.app_core
.config
.get_string("ui_path")
.unwrap_or_else(|_| "/ui".to_string());
if let Ok(ui_config) = app_dao.app_core.config.get_string("ui_dir") {
let mut ui_dir = PathBuf::from_str(&ui_config);
if let Ok(ref ui_buf) = ui_dir {
if !ui_buf.exists() && !ui_buf.is_absolute() {
let cargo_dir = env!("CARGO_MANIFEST_DIR");
ui_path = PathBuf::from_str(&format!("{}/{}", cargo_dir, ui_dir))
ui_dir = PathBuf::from_str(&format!("{}/{}", cargo_dir, ui_config))
}
}
if let Ok(ui_buf) = ui_path {
if let Ok(ui_buf) = ui_dir {
if ui_buf.exists() {
return app.service(web::redirect("/ui", "/ui/")).service(
actix_files::Files::new("/ui/", ui_buf)
.index_file("index.html")
.show_files_listing(),
);
let ui_path_full = ui_path.trim_matches('/').to_string() + "/";
return app
.service(web::redirect(
ui_path.trim_matches('/').to_string(),
ui_path_full.to_owned(),
))
.service(
actix_files::Files::new(&ui_path_full, ui_buf)
.index_file("index.html")
.show_files_listing(),
);
}
}
warn!("not find ui dir : {}", ui_dir);
warn!("not find ui dir : {}", ui_config);
} else {
info!("not set ui dir");
}
Expand Down

0 comments on commit 7f4c560

Please sign in to comment.