From 03d07fc56b26897dcec530630b07d18fc606d364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipi=C5=84ski?= Date: Fri, 17 Nov 2023 05:06:57 +0100 Subject: [PATCH 1/2] fix: remove static_routers from api - static_routers are not present in api anyway and it breaks generated project --- src/template/src/routers/mod.hbs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/template/src/routers/mod.hbs b/src/template/src/routers/mod.hbs index 137ef3b..e4c218d 100644 --- a/src/template/src/routers/mod.hbs +++ b/src/template/src/routers/mod.hbs @@ -81,8 +81,7 @@ 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()) From 3a71fee4c3c22ed2c3992e1a4ebfb673e7483b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lipi=C5=84ski?= Date: Fri, 17 Nov 2023 05:08:26 +0100 Subject: [PATCH 2/2] FIX: create assets folder in generated web project - was breaking run FIX: use and generate routers_static - file was missing in generated project --- src/utils/create_project.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/utils/create_project.rs b/src/utils/create_project.rs index 1866546..3cc2a12 100644 --- a/src/utils/create_project.rs +++ b/src/utils/create_project.rs @@ -184,6 +184,7 @@ fn write_project_file( let (src_path, router_path) = create_basic_file(project_path, &handlebars, &data)?; + if is_web_site { //templates let template_path = project_path.join("templates"); @@ -202,9 +203,13 @@ fn write_project_file( handle_404_file.write_all(handle_404_template_rendered.as_bytes())?; //assets let assets_path = project_path.join("assets"); + std::fs::create_dir_all(&assets_path)?; + + //assets/favicon.ico let favicon_bytes = include_bytes!("../template/assets/favicon.ico"); let mut favicon_file = File::create(assets_path.join("favicon.ico"))?; + favicon_file.write_all(favicon_bytes)?; if need_db_conn { //assets/js @@ -260,6 +265,13 @@ fn write_project_file( let router_user_rendered = handlebars.render_template(router_user_template, &data)?; let mut router_user_file = File::create(router_path.join("user.rs"))?; router_user_file.write_all(router_user_rendered.as_bytes())?; + + //src/router/static_routers.rs + let router_static_routers_template = include_str!("../template/src/routers/static_routers.hbs"); + let router_static_routers_rendered = handlebars.render_template(router_static_routers_template, &data)?; + let mut router_static_routers_file = File::create(router_path.join("static_routers.rs"))?; + router_static_routers_file.write_all(router_static_routers_rendered.as_bytes())?; + //src/services let services_path = src_path.join("services"); std::fs::create_dir_all(&services_path)?; @@ -273,6 +285,7 @@ fn write_project_file( let services_user_rendered = handlebars.render_template(services_user_template, &data)?; let mut services_user_file = File::create(services_path.join("user.rs"))?; services_user_file.write_all(services_user_rendered.as_bytes())?; + //src/utils let utils_path = src_path.join("utils"); std::fs::create_dir_all(&utils_path)?; @@ -649,6 +662,12 @@ fn create_basic_file( let mut router_demo_file = File::create(router_path.join("demo.rs"))?; router_demo_file.write_all(router_demo_rendered.as_bytes())?; + //src/router/static_routers.rs + // let router_static_routers_template = include_str!("../template/src/routers/static_routers.hbs"); + // let router_static_routers_rendered = handlebars.render_template(router_static_routers_template, &data)?; + // let mut router_static_routers_file = File::create(router_path.join("static_routers.rs"))?; + // router_static_routers_file.write_all(router_static_routers_rendered.as_bytes())?; + Ok((src_path, router_path)) }