rcpp_framework/rdn_application.cpp

88 lines
1.8 KiB
C++
Raw Normal View History

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>
#include "core/file_cache.h"
#include "core/handler_instance.h"
#include "core/database_manager.h"
void RDNApplication::index(Object *instance, Request *request) {
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 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);
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) {
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();
index_func = HandlerInstance(index);
2020-11-25 00:20:41 +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();
//middlewares.push_back(RDNApplication::session_middleware_func);
2020-11-25 00:20:41 +01:00
}
void RDNApplication::migrate() {
message_page->migrate();
}
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();
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
}