diff --git a/app/wp_application.cpp b/app/wp_application.cpp index 1a8529f..5435f6b 100644 --- a/app/wp_application.cpp +++ b/app/wp_application.cpp @@ -21,12 +21,12 @@ void WPApplication::index(Object *instance, Request *request) { } void WPApplication::blog(Object *instance, Request *request) { - request->body += "test"; + request->body += "test blog"; request->compile_and_send_body(); } void WPApplication::routing_middleware(Object *instance, Request *request) { - std::string path = request->get_path_full(); + String path = request->get_path_full(); WPApplication *app = Object::cast_to(instance); @@ -36,19 +36,26 @@ void WPApplication::routing_middleware(Object *instance, Request *request) { return; } + bool handled = false; + if (request->get_path_segment_count() == 0) { + handled = true; + request->handler_instance = app->index_func; } else { - const std::string main_route = request->get_current_path_segment(); + + + const String main_route = request->get_current_path_segment(); request->push_path(); if (main_route == "blog") { + handled = true; request->handler_instance = app->blog_func; } } - if (!request->handler_instance.handler_func) { + if (!handled) { app->send_error(404, request); return; diff --git a/main.cpp b/main.cpp index f6889e6..b12e7ac 100644 --- a/main.cpp +++ b/main.cpp @@ -16,6 +16,7 @@ #include "core/settings.h" #include "app/wp_downloader.h" +#include "app/wp_application.h" void initialize_backends() { initialize_database_backends(); @@ -65,12 +66,11 @@ int main(int argc, char **argv, char **envp) { delete dbm; } else { - /* FileCache *file_cache = new FileCache(true); file_cache->wwwroot = "./www"; file_cache->wwwroot_refresh_cache(); - DWebApplication *app = new DWebApplication(); + WPApplication *app = new WPApplication(); app->load_settings(); app->setup_routes(); app->setup_middleware(); @@ -81,7 +81,6 @@ int main(int argc, char **argv, char **envp) { delete app; delete file_cache; - */ } delete settings;