Run the web app when launched without parameters. Also cleanups.

This commit is contained in:
Relintai 2021-11-21 14:55:34 +01:00
parent 1044749d2a
commit a6a8b11871
2 changed files with 13 additions and 7 deletions

View File

@ -21,12 +21,12 @@ void WPApplication::index(Object *instance, Request *request) {
} }
void WPApplication::blog(Object *instance, Request *request) { void WPApplication::blog(Object *instance, Request *request) {
request->body += "test"; request->body += "test blog";
request->compile_and_send_body(); request->compile_and_send_body();
} }
void WPApplication::routing_middleware(Object *instance, Request *request) { 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<WPApplication>(instance); WPApplication *app = Object::cast_to<WPApplication>(instance);
@ -36,19 +36,26 @@ void WPApplication::routing_middleware(Object *instance, Request *request) {
return; return;
} }
bool handled = false;
if (request->get_path_segment_count() == 0) { if (request->get_path_segment_count() == 0) {
handled = true;
request->handler_instance = app->index_func; request->handler_instance = app->index_func;
} else { } else {
const std::string main_route = request->get_current_path_segment();
const String main_route = request->get_current_path_segment();
request->push_path(); request->push_path();
if (main_route == "blog") { if (main_route == "blog") {
handled = true;
request->handler_instance = app->blog_func; request->handler_instance = app->blog_func;
} }
} }
if (!request->handler_instance.handler_func) { if (!handled) {
app->send_error(404, request); app->send_error(404, request);
return; return;

View File

@ -16,6 +16,7 @@
#include "core/settings.h" #include "core/settings.h"
#include "app/wp_downloader.h" #include "app/wp_downloader.h"
#include "app/wp_application.h"
void initialize_backends() { void initialize_backends() {
initialize_database_backends(); initialize_database_backends();
@ -65,12 +66,11 @@ int main(int argc, char **argv, char **envp) {
delete dbm; delete dbm;
} else { } else {
/*
FileCache *file_cache = new FileCache(true); FileCache *file_cache = new FileCache(true);
file_cache->wwwroot = "./www"; file_cache->wwwroot = "./www";
file_cache->wwwroot_refresh_cache(); file_cache->wwwroot_refresh_cache();
DWebApplication *app = new DWebApplication(); WPApplication *app = new WPApplication();
app->load_settings(); app->load_settings();
app->setup_routes(); app->setup_routes();
app->setup_middleware(); app->setup_middleware();
@ -81,7 +81,6 @@ int main(int argc, char **argv, char **envp) {
delete app; delete app;
delete file_cache; delete file_cache;
*/
} }
delete settings; delete settings;