Skip to content

Commit

Permalink
adds flag to avoid adding blueprints multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoPetrilli authored and gittiver committed Mar 10, 2024
1 parent 55e604f commit db059ce
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace crow

std::string rule_;
std::string name_;
bool added_ = false;
bool added_{false};

std::unique_ptr<BaseRule> rule_to_upgrade_;

Expand Down Expand Up @@ -1164,6 +1164,14 @@ namespace crow
return static_dir_;
}

void set_added() {
added_ = true;
}

bool is_added() {
return added_;
}

DynamicRule& new_rule_dynamic(const std::string& rule)
{
std::string new_rule = '/' + prefix_ + rule;
Expand Down Expand Up @@ -1236,6 +1244,7 @@ namespace crow
CatchallRule catchall_rule_;
std::vector<Blueprint*> blueprints_;
detail::middleware_indices mw_indices_;
bool added_{false};

friend class Router;
};
Expand Down Expand Up @@ -1347,6 +1356,9 @@ namespace crow
for (unsigned i = 0; i < blueprints.size(); i++)
{
Blueprint* blueprint = blueprints[i];

if (blueprint->is_added()) continue;

if (blueprint->static_dir_ == "" && blueprint->all_rules_.empty())
{
std::vector<HTTPMethod> methods;
Expand All @@ -1373,6 +1385,7 @@ namespace crow
}
validate_bp(blueprint->blueprints_, current_mw);
current_mw.pop_back(blueprint->mw_indices_);
blueprint->set_added();
}
}

Expand Down

0 comments on commit db059ce

Please sign in to comment.