2020-11-25 00:20:41 +01:00
|
|
|
#include "rdn_application.h"
|
|
|
|
|
2020-11-25 13:28:34 +01:00
|
|
|
#include "core/request.h"
|
2020-11-25 00:20:41 +01:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2020-11-25 14:53:53 +01:00
|
|
|
#include "core/file_cache.h"
|
|
|
|
|
2020-12-01 12:56:04 +01:00
|
|
|
#include "core/handler_instance.h"
|
|
|
|
|
2020-12-01 18:29:41 +01:00
|
|
|
#include "core/database_manager.h"
|
|
|
|
|
2020-12-01 12:56:04 +01:00
|
|
|
void RDNApplication::index(Object *instance, Request *request) {
|
2020-11-25 14:53:53 +01:00
|
|
|
std::string body;
|
|
|
|
|
|
|
|
if (FileCache::get_singleton()->get_cached_body("index", &body)) {
|
|
|
|
request->response->setBody(body);
|
|
|
|
|
2020-11-25 21:00:22 +01:00
|
|
|
return;
|
2020-11-25 14:53:53 +01:00
|
|
|
}
|
|
|
|
|
2020-11-25 21:00:22 +01:00
|
|
|
SiteTheme::default_theme->render_index_page(request, &body);
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2020-11-25 21:00:22 +01:00
|
|
|
FileCache::get_singleton()->set_cached_body("index", body);
|
2020-11-25 00:20:41 +01:00
|
|
|
|
|
|
|
request->response->setBody(body);
|
2020-11-26 11:26:02 +01:00
|
|
|
request->send();
|
2020-11-25 00:20:41 +01:00
|
|
|
}
|
|
|
|
|
2020-12-01 17:01:59 +01:00
|
|
|
void RDNApplication::session_middleware_func(Object *instance, Request *request) {
|
2020-11-26 12:02:58 +01:00
|
|
|
std::cout << "test: session_middleware_func called" << std::endl;
|
|
|
|
|
|
|
|
//if fail
|
|
|
|
//request->send(); in middleware
|
|
|
|
|
|
|
|
request->next_stage();
|
2020-11-25 00:20:41 +01:00
|
|
|
}
|
|
|
|
|
2020-12-01 17:01:59 +01:00
|
|
|
void RDNApplication::message_page_func(Object *instance, Request *request) {
|
|
|
|
dynamic_cast<MessagePage *>(instance)->index(request);
|
|
|
|
}
|
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
void RDNApplication::setup_routes() {
|
|
|
|
Application::setup_routes();
|
|
|
|
|
2020-12-01 12:56:04 +01:00
|
|
|
index_func = HandlerInstance(index);
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2020-12-01 12:56:04 +01:00
|
|
|
main_route_map["asd"] = HandlerInstance(index);
|
2020-12-01 17:01:59 +01:00
|
|
|
main_route_map["message_page"] = HandlerInstance(message_page_func, message_page);
|
2020-11-25 00:20:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RDNApplication::setup_middleware() {
|
|
|
|
Application::setup_middleware();
|
|
|
|
|
2020-11-26 12:10:21 +01:00
|
|
|
//middlewares.push_back(RDNApplication::session_middleware_func);
|
2020-11-25 00:20:41 +01:00
|
|
|
}
|
|
|
|
|
2020-12-01 17:01:59 +01:00
|
|
|
RDNApplication::RDNApplication() :
|
|
|
|
Application() {
|
2020-11-25 21:00:22 +01:00
|
|
|
|
|
|
|
SiteTheme *t = new TestSiteTheme();
|
|
|
|
t->register_theme();
|
|
|
|
t->set_theme_as_default();
|
|
|
|
|
|
|
|
themes.push_back(t);
|
|
|
|
|
|
|
|
t = new TestSiteTheme2();
|
|
|
|
t->register_theme();
|
|
|
|
|
|
|
|
themes.push_back(t);
|
2020-12-01 17:01:59 +01:00
|
|
|
|
|
|
|
message_page = new MessagePage();
|
2020-12-01 18:29:41 +01:00
|
|
|
message_page->db = DatabaseManager::get_singleton()->databases[0];
|
2020-11-25 00:20:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RDNApplication::~RDNApplication() {
|
2020-11-25 21:00:22 +01:00
|
|
|
for (uint32_t i = 0; i < themes.size(); ++i) {
|
|
|
|
delete themes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
themes.clear();
|
2020-12-01 17:01:59 +01:00
|
|
|
|
|
|
|
delete message_page;
|
2020-11-25 00:20:41 +01:00
|
|
|
}
|