Remove the code that isn't needed here anymore.

This commit is contained in:
Relintai 2020-12-25 21:12:17 +01:00
parent 4ef17eee09
commit 842e785da4
3 changed files with 0 additions and 221 deletions

View File

@ -1,95 +0,0 @@
#include <string.h>
#include <iostream>
#include <string>
#include "core/application.h"
#include "core/file_cache.h"
#include "core/http_server.h"
#include "rdn_application.h"
#include "core/database_manager.h"
#include "database/db_init.h"
#include "core/settings.h"
#define MAIN_CLASS RDNApplication
void create_databases() {
Settings *settings = Settings::get_singleton();
if (!settings) {
printf("create_databases: Settings singleton is null!");
return;
}
/*
rapidjson::Value dbs = settings->settings["databases"];
if (!dbs.IsArray()) {
printf("create_databases: dbs !dbs.IsArray()!");
return;
}
*/
DatabaseManager *dbm = DatabaseManager::get_singleton();
uint32_t index = dbm->create_database("mysql");
Database *db = dbm->databases[0];
//db->_builder_creation_func = MysqlQueryBuilder::create;
db->connect("");
}
int main(int argc, char **argv) {
bool migrate = false;
for (int i = 1; i < argc; ++i) {
const char *a = argv[i];
if (a[0] == 'm') {
migrate = true;
}
}
initialize_database_backends();
Settings *settings = new Settings(true);
settings->parse_file("settings.json");
FileCache *file_cache = new FileCache(true);
file_cache->wwwroot = "./www";
file_cache->wwwroot_refresh_cache();
DatabaseManager *dbm = new DatabaseManager();
create_databases();
Application *app = new MAIN_CLASS();
app->load_settings();
app->setup_routes();
app->setup_middleware();
HTTPServer *server = new HTTPServer();
server->port = 8080;
server->initialize();
if (!migrate) {
server->main_loop();
} else {
printf("Running migrations.\n");
app->migrate();
}
delete server;
delete app;
delete dbm;
delete file_cache;
delete settings;
return 0;
}

View File

@ -1,98 +0,0 @@
#include "rdn_application.h"
#include "core/request.h"
#include <iostream>
#include "core/file_cache.h"
#include "core/handler_instance.h"
#include "core/database_manager.h"
#include "core/html_builder.h"
void RDNApplication::index(Object *instance, Request *request) {
std::string body;
if (FileCache::get_singleton()->get_cached_body("index", &body)) {
request->response->setBody(body);
return;
}
HTMLBuilder b;
b.h1();
b.w("Testh1");
b.ch1();
b.h2()->cls("tcls")->id("tid");
b.w("Testh2");
b.ch2();
b.br();
b.p();
b.w("Test HTML Body HTMLBuilder");
b.cp();
b.form()->method("post")->href("/");
//->str("/") is a temp hack
b.input()->type("text")->str("/");
b.input()->type("submit")->str("/");
b.cform();
request->body = b.result;
//request->body.append("<p>Test HTML Body</p>");
request->compile_body();
FileCache::get_singleton()->set_cached_body("index", request->compiled_body);
request->send();
}
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();
}
void RDNApplication::message_page_func(Object *instance, Request *request) {
dynamic_cast<MessagePage *>(instance)->index(request);
}
void RDNApplication::setup_routes() {
Application::setup_routes();
index_func = HandlerInstance(index);
main_route_map["asd"] = HandlerInstance(index);
main_route_map["message_page"] = HandlerInstance(message_page_func, message_page);
}
void RDNApplication::setup_middleware() {
Application::setup_middleware();
//middlewares.push_back(RDNApplication::session_middleware_func);
}
void RDNApplication::migrate() {
message_page->migrate();
}
RDNApplication::RDNApplication() :
Application() {
message_page = new MessagePage();
message_page->db = DatabaseManager::get_singleton()->databases[0];
}
RDNApplication::~RDNApplication() {
delete message_page;
}

View File

@ -1,28 +0,0 @@
#ifndef RDN_APPLICATION_H
#define RDN_APPLICATION_H
#include "core/application.h"
#include "core/object.h"
#include "modules/message_page/message_page.h"
class RDNApplication : public Application {
public:
static void index(Object *instance, Request *request);
static void session_middleware_func(Object* instance, Request *request);
static void message_page_func(Object *instance, Request *request);
virtual void setup_routes();
virtual void setup_middleware();
virtual void migrate();
RDNApplication();
~RDNApplication();
MessagePage *message_page;
};
#endif