Crow
Crow copied to clipboard
Buggy Blueprint Catchall behavior
Hello, first of all I wanted to say that this is an amazing library, and thank you to all the contributors.
As I've been using Crow (master branch), I encountered strange behavior with blueprint catchall routing.
For example, if the structure of my routes are,
root
-> api
(bp) -> auth
(bp), each with its own catchall route,
When I access GET "/api/auth/<404-route>" , it correctly lands on the auth
bp's catchall.
But when I access GET "/api/<404-route>", it uses the root app's catchall and skips the api's.
Here is a minimal example running off of the master branch demonstrating the bug:
#include <crow.h>
int main()
{
crow::Crow<> app;
crow::Blueprint api("api");
crow::Blueprint auth("auth");
// set up regular routes
CROW_ROUTE(app, "/")([]() {
return "/ route was hit!";
});
CROW_BP_ROUTE(api, "/")([]() {
return "/api route was hit!";
});
CROW_BP_ROUTE(auth, "/")([]() {
return "/api/auth route was hit!";
});
// setup catchall routes
CROW_CATCHALL_ROUTE(app)([]() {
return "main catchall route was hit!";
});
CROW_BP_CATCHALL_ROUTE(auth)([]() {
return "auth catchall route was hit!";
});
CROW_BP_CATCHALL_ROUTE(api)([]() {
return "api catchall route was hit!";
});
// mount blueprints
api.register_blueprint(auth);
app.register_blueprint(api);
app.port(3001).run();
return 0;
}
In my current app, all first-level blueprint catchall routes are similarly broken.
I want to add that there appears to be no middleware that is activated on the main catchall route. E.g. one of my custom middlewares sets a bunch of security headers, but I do not receive the headers when testing the catchall. If I attempt to retrieve any of my custom middleware contexts there is a memory access error.