diff --git a/core/application.cpp b/core/application.cpp index 2fa0664..664f645 100644 --- a/core/application.cpp +++ b/core/application.cpp @@ -19,20 +19,10 @@ void Application::setup_routes() { } void Application::setup_middleware() { + middlewares.push_back(Application::default_routing_middleware); } -void Application::default_fallback_error_handler(int error_code, Request *request) { - request->response->setBody(default_generic_error_body); - request->send(); -} - -void Application::default_404_error_handler(int error_code, Request *request) { - request->response->setBody(default_error_404_body); - request->send(); -} - -void Application::handle_request(Request *request) { - +void Application::default_routing_middleware(Request *request) { std::string path = request->http_parser->getPath(); if (FileCache::get_singleton()->wwwroot_has_file(path)) { @@ -68,8 +58,23 @@ void Application::handle_request(Request *request) { } request->handler_func = func; + request->next_stage(); +} + +void Application::default_fallback_error_handler(int error_code, Request *request) { + request->response->setBody(default_generic_error_body); + request->send(); +} + +void Application::default_404_error_handler(int error_code, Request *request) { + request->response->setBody(default_error_404_body); + request->send(); +} + +void Application::handle_request(Request *request) { request->middleware_stack = &middlewares; + //note that middlewares handle the routing -> Application::default_routing_middleware by default request->next_stage(); } diff --git a/core/application.h b/core/application.h index 67f0f36..96f6a29 100644 --- a/core/application.h +++ b/core/application.h @@ -23,6 +23,8 @@ public: virtual void setup_routes(); virtual void setup_middleware(); + static void default_routing_middleware(Request *request); + Application(); virtual ~Application(); diff --git a/rdn_application.cpp b/rdn_application.cpp index 86934c2..68ae951 100644 --- a/rdn_application.cpp +++ b/rdn_application.cpp @@ -43,7 +43,7 @@ void RDNApplication::setup_routes() { void RDNApplication::setup_middleware() { Application::setup_middleware(); - middlewares.push_back(RDNApplication::session_middleware_func); + //middlewares.push_back(RDNApplication::session_middleware_func); } RDNApplication::RDNApplication() : Application() {