diff --git a/assets/favicon.ico b/src/template/assets/favicon.ico similarity index 100% rename from assets/favicon.ico rename to src/template/assets/favicon.ico diff --git a/assets/js/alpinejs.js b/src/template/assets/js/alpinejs.js similarity index 100% rename from assets/js/alpinejs.js rename to src/template/assets/js/alpinejs.js diff --git a/assets/js/sweetalert2.js b/src/template/assets/js/sweetalert2.js similarity index 100% rename from assets/js/sweetalert2.js rename to src/template/assets/js/sweetalert2.js diff --git a/assets/js/tailwindcss.js b/src/template/assets/js/tailwindcss.js similarity index 100% rename from assets/js/tailwindcss.js rename to src/template/assets/js/tailwindcss.js diff --git a/src/template/src/routers/mod.hbs b/src/template/src/routers/mod.hbs index 39b1a1c..137ef3b 100644 --- a/src/template/src/routers/mod.hbs +++ b/src/template/src/routers/mod.hbs @@ -15,6 +15,7 @@ use self::{ }; pub mod demo; pub mod user; +mod static_routers; pub fn router() -> Router { let mut no_auth_routers = vec![ @@ -33,6 +34,8 @@ pub fn router() -> Router { .delete(delete_user), ), ]; + let static_routers = static_routers::create_static_routers(); + no_auth_routers.extend(static_routers); let router = Router::new() .hoop(Logger::new()) .hoop(CatchPanic::new()) @@ -78,6 +81,8 @@ pub fn router() -> Router { .delete(delete_user), ), ]; + let static_routers = static_routers::create_static_routers(); + no_auth_routers.extend(static_routers); let router = Router::new() .hoop(Logger::new()) .hoop(CatchPanic::new()) diff --git a/src/template/src/routers/static_routers.hbs b/src/template/src/routers/static_routers.hbs new file mode 100644 index 0000000..8800d53 --- /dev/null +++ b/src/template/src/routers/static_routers.hbs @@ -0,0 +1,23 @@ +use rust_embed::RustEmbed; +use salvo::{Router, serve_static::static_embed, endpoint, Response, http::ResBody, hyper::body::Bytes}; + +#[derive(RustEmbed)] +#[folder = "assets"] +struct Assets; + +pub fn create_static_routers() -> Vec { + {{#if need_db_conn}} + let static_router = Router::with_path("assets/<**path>").get(static_embed::()); + let icon_router = Router::with_path("favicon.ico").get(get_icon); + vec![static_router,icon_router] + {{else}} + let icon_router = Router::with_path("favicon.ico").get(get_icon); + vec![icon_router] + {{/if}} +} + +#[endpoint(tags("comm"))] +pub async fn get_icon(res: &mut Response) { + let icon = Assets::get("favicon.ico").unwrap(); + res.body(ResBody::Once(Bytes::from(icon.data.to_vec()))); +} diff --git a/src/template/templates/404.hbs b/src/template/templates/404.hbs index dd97fe6..0164311 100644 --- a/src/template/templates/404.hbs +++ b/src/template/templates/404.hbs @@ -4,8 +4,8 @@ 404 {{page_not_found}} - - + + diff --git a/src/template/templates/login.hbs b/src/template/templates/login.hbs index cfe249d..bc124fa 100644 --- a/src/template/templates/login.hbs +++ b/src/template/templates/login.hbs @@ -80,9 +80,9 @@ - - - + + + - - + + +