Comments (4)
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;
}
});
from beasthttp.
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);
?
from beasthttp.
The point is that it does not seem to work to use chainable middlewares for e.g. logging, authentication etc for router.use
one can use the middlewares only wity router.get|post|put etc
Using an auth middleware in all get methods is pretty verbose when you can just add one middleware to the router...
E.g. all routes starting with /api/
shall be authenticated with e.g. a token
And all other routes are serving static content which is public
Furthermore all routes with /api/admin/
shall be send through an authorization middleware after the authentication middleware
from beasthttp.
did it myself as I also needed other features...
Example of what I wished in this issue: https://github.com/expresscpp/expresscpp/blob/master/example/router.cpp
from beasthttp.
Related Issues (20)
- turn header-only to static library for saving time HOT 3
- returning r-value reference to stack allocated type (memory corruption) HOT 5
- turn on SO_REUSEADDR for listening socket (always, preferably) HOT 3
- Are there any demo examples that show the windows use cases? HOT 2
- No proper tags for releases HOT 1
- Doxygen info
- Build static libs
- Concurrency problems with router params HOT 3
- #if not defined
- 项目通用性疑问?
- Using `use` for creating modular routes results in errors.
- Error compilation on Boost version: 1.69.0 GNU 5.4.0
- [MSVC] warning C4067: unexpected tokens following preprocessor directive - expected a newline
- Windows MSVC support request
- Do not use deprecated interfaces
- Not working with Boost libraries, newer than 1.73.0
- (feature request) HTTP/2 Functionality Request HOT 1
- Trouble compliling in Ubuntu 22.04.1 LTS using gcc with Makefiles HOT 1
- Lib status?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beasthttp.