From 9669fa63365fe135bc2449811b9f591ff69a0671 Mon Sep 17 00:00:00 2001 From: Morphone Date: Mon, 11 Nov 2024 23:41:19 +0100 Subject: [PATCH 1/2] refactor: make validate_bp independent from CROW_DISABLE_STATIC_DIR --- include/crow/app.h | 11 +++++------ tests/unittest.cpp | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/crow/app.h b/include/crow/app.h index 25592da69..7628cfbf8 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -460,8 +460,8 @@ namespace crow } #endif - /// \brief Apply blueprints - void add_blueprint() + /// \brief Apply blueprints static routes + void add_blueprint_static_dirs() { #if defined(__APPLE__) || defined(__MACH__) if (router_.blueprints().empty()) return; @@ -480,9 +480,7 @@ namespace crow res.set_static_file_info_unsafe(static_dir_ + file_path_partial); res.end(); }); - } - - router_.validate_bp(); + } } /// \brief Go through the rules, upgrade them if possible, and add them to the list of rules @@ -503,13 +501,14 @@ namespace crow void validate() { router_.validate(); + router_.validate_bp(); } /// \brief Run the server void run() { #ifndef CROW_DISABLE_STATIC_DIR - add_blueprint(); + add_blueprint_static_dirs(); add_static_dir(); #endif validate(); diff --git a/tests/unittest.cpp b/tests/unittest.cpp index 53f083c07..bcb5f9624 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -3643,7 +3643,7 @@ TEST_CASE("blueprint") bp.register_blueprint(sub_bp); sub_bp.register_blueprint(sub_sub_bp); - app.add_blueprint(); + app.add_blueprint_static_dirs(); app.add_static_dir(); app.validate(); From ff4720b3d166eb4ab8e3541612ed241e66b2021f Mon Sep 17 00:00:00 2001 From: Morphone Date: Tue, 12 Nov 2024 01:38:28 +0000 Subject: [PATCH 2/2] fix: add blueprints first --- include/crow/app.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/crow/app.h b/include/crow/app.h index 7628cfbf8..79fdad59b 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -500,8 +500,8 @@ namespace crow /// \brief A wrapper for `validate()` in the router void validate() { - router_.validate(); - router_.validate_bp(); + router_.validate_bp(); + router_.validate(); } /// \brief Run the server