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-11-25 00:20:41 +01:00
|
|
|
void RDNApplication::index(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
|
|
|
}
|
|
|
|
|
|
|
|
void RDNApplication::session_middleware_func(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
|
|
|
}
|
|
|
|
|
|
|
|
void RDNApplication::setup_routes() {
|
|
|
|
Application::setup_routes();
|
|
|
|
|
|
|
|
index_func = index;
|
|
|
|
|
|
|
|
main_route_map["asd"] = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-11-25 21:00:22 +01:00
|
|
|
RDNApplication::RDNApplication() : Application() {
|
|
|
|
|
|
|
|
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-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-11-25 00:20:41 +01:00
|
|
|
}
|