Skip to content

Commit

Permalink
set crow static directory and template directory in case of an empty …
Browse files Browse the repository at this point in the history
…static_dir or template dir parameter to blueprints url prefix as default.

added also error log output in case of a top level blueprint with empty static_dir (should not happen anymore due to above fix, but at least not silently ignored)
  • Loading branch information
gittiver committed Aug 5, 2024
1 parent 31ca145 commit 9600af3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,10 @@ namespace crow

for (Blueprint* bp : router_.blueprints())
{
if (bp->static_dir().empty()) continue;

if (bp->static_dir().empty()) {
CROW_LOG_ERROR << "Blueprint " << bp->prefix() << " and its sub-blueprints ignored due to empty static directory.";
continue;
}
auto static_dir_ = crow::utility::normalize_path(bp->static_dir());

bp->new_rule_tagged<crow::black_magic::get_parameter_tag(CROW_STATIC_ENDPOINT)>(CROW_STATIC_ENDPOINT)([static_dir_](crow::response& res, std::string file_path_partial) {
Expand Down
9 changes: 6 additions & 3 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1095,16 +1095,19 @@ namespace crow // NOTE: Already documented in "crow/app.h"
Node head_;
};

/// A blueprint can be considered a smaller section of a Crow app, specifically where the router is conecerned.
/// A blueprint can be considered a smaller section of a Crow app, specifically where the router is concerned.

///
/// You can use blueprints to assign a common prefix to rules' prefix, set custom static and template folders, and set a custom catchall route.
/// You can also assign nest blueprints for maximum Compartmentalization.
class Blueprint
{
public:
Blueprint(const std::string& prefix):
prefix_(prefix){};
Blueprint(const std::string& prefix)
: prefix_(prefix),
static_dir_(prefix),
templates_dir_(prefix)
{};

Blueprint(const std::string& prefix, const std::string& static_dir):
prefix_(prefix), static_dir_(static_dir){};
Expand Down

0 comments on commit 9600af3

Please sign in to comment.