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) {
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<WPApplication>(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;

View File

@ -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;