diff options
Diffstat (limited to 'include/crow.h')
-rw-r--r-- | include/crow.h | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/include/crow.h b/include/crow.h index a018f31..a4b82df 100644 --- a/include/crow.h +++ b/include/crow.h @@ -13,12 +13,9 @@ #include "http_server.h" #include "utility.h" #include "routing.h" -#include "middleware_impl.h" +#include "middleware_context.h" #include "http_request.h" -// TEST -#include <iostream> - #define CROW_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url) namespace crow @@ -28,13 +25,14 @@ namespace crow { public: using self_t = Crow; + using server_t = Server<Crow, Middlewares...>; Crow() { } void handle(const request& req, response& res) { - return router_.handle(req, res); + router_.handle(req, res); } template <uint64_t Tag> @@ -71,7 +69,7 @@ namespace crow void run() { validate(); - Server<self_t> server(this, port_, concurrency_); + server_t server(this, port_, concurrency_); server.run(); } @@ -84,19 +82,17 @@ namespace crow // middleware using context_t = detail::context<Middlewares...>; template <typename T> - T& get_middleware_context(request& req) + typename T::context& get_middleware_context(const request& req) { static_assert(black_magic::contains<T, Middlewares...>::value, "App doesn't have the specified middleware type."); auto& ctx = *reinterpret_cast<context_t*>(req.middleware_context); - return ctx.get<T>(); + return ctx.template get<T>(); } private: uint16_t port_ = 80; uint16_t concurrency_ = 1; - std::tuple<Middlewares...> middlewares_; - Router router_; }; template <typename ... Middlewares> |