-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add possibility of using middlewares with use
, not only in http methods
#31
Comments
my first guess was to add the missing template to basic_router.cpp though no luck -> does not work either (compiling though now functioning): template <class... OnRequest>
void use(resource_regex_type const& path_to_resource, const base_type& other, OnRequest&&... on_request) {
add_resource_cb_without_method(path_to_resource, storage_type{std::forward<OnRequest>(on_request)...});
base_type::use(path_to_resource, other);
} main_router.use(route_api_str, api_router, [](auto request, auto context) {
if (request[boost::beast::http::field::authorization] != "my_token") {
context.send(make_401<boost::beast::http::string_body>(request));
std::cout << "asdf" << std::endl;
return;
}
}); |
If you still need to, but why not do this: api_router.get("^/1$",
std::bind(authMiddleware, std::_1, std::_2, std::_3),
[](auto request, auto context) {
/// ...
});
api_router.get("^/2$",
std::bind(authMiddleware, std::_1, std::_2, std::_3),
[](auto request, auto context) {
/// ...
});
// ...
main_router.use("/numbers", api_router); ? |
The point is that it does not seem to work to use chainable middlewares for e.g. logging, authentication etc for Using an auth middleware in all get methods is pretty verbose when you can just add one middleware to the router... |
did it myself as I also needed other features... |
middlewares are great to check for credentials and permissions e.g. authentication and authorization.
basically all routes would need authentication, instead of adding a middleware to all http methods
The text was updated successfully, but these errors were encountered: