diff --git a/core/http/web_root.cpp b/core/http/web_root.cpp index 9a8e1a2..6cdffae 100644 --- a/core/http/web_root.cpp +++ b/core/http/web_root.cpp @@ -12,12 +12,13 @@ #include #include -void WebRoot::load_settings() { +void WebRoot::setup() { + setup_error_handlers(); + setup_middleware(); } -void WebRoot::setup_routes() { +void WebRoot::setup_error_handlers() { default_error_handler_func = WebRoot::default_fallback_error_handler; - error_handler_map[404] = WebRoot::default_404_error_handler; } @@ -90,19 +91,12 @@ bool WebRoot::try_send_wwwroot_file(Request *request) { return false; } -void WebRoot::send_error(int error_code, Request *request) { - -} - void WebRoot::send_file(const std::string &path, Request *request) { std::string fp = FileCache::get_singleton()->wwwroot + path; request->send_file(fp); } -void WebRoot::migrate() { -} - void WebRoot::register_request_update(Request *request) { std::lock_guard lock(_update_registered_requests_mutex); @@ -135,12 +129,13 @@ void WebRoot::update() { WebRoot::WebRoot() : WebRouterNode() { + + setup(); } WebRoot::~WebRoot() { - main_route_map.clear(); error_handler_map.clear(); - middlewares.clear(); + _middlewares.clear(); } std::string WebRoot::default_error_404_body = "404 :("; diff --git a/core/http/web_root.h b/core/http/web_root.h index 54b73d9..8164c0d 100644 --- a/core/http/web_root.h +++ b/core/http/web_root.h @@ -17,13 +17,10 @@ class Request; // FileCache -> set up, for this webroot, don't use singleton -// clean up unused things here // remove handler instances! // Update the rest of the modules to the new systems -// remove middleware stack from request - class WebRoot : public WebRouterNode { RCPP_OBJECT(WebRoot, WebRouterNode); @@ -35,20 +32,17 @@ public: void handle_error_send_request(Request *request, const int error_code); bool try_send_wwwroot_file(Request *request); - void send_error(int error_code, Request *request); void send_file(const std::string &path, Request *request); static void default_fallback_error_handler(Request *request, int error_code); static void default_404_error_handler(Request *request, int error_code); - virtual void load_settings(); - virtual void setup_routes(); + virtual void setup(); + virtual void setup_error_handlers(); virtual void setup_middleware(); void default_routing_middleware(Object *instance, Request *request); - virtual void migrate(); - void register_request_update(Request *request); void unregister_request_update(Request *request); void update(); @@ -57,10 +51,6 @@ public: virtual ~WebRoot(); public: - HandlerInstance index_func; - std::map main_route_map; - std::vector middlewares; - Vector > _middlewares; std::map > error_handler_map;