2020-12-08 16:22:18 +01:00
|
|
|
#include <string.h>
|
2020-11-24 15:41:18 +01:00
|
|
|
#include <iostream>
|
2020-11-25 00:20:41 +01:00
|
|
|
#include <string>
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-11-25 13:28:34 +01:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/file_cache.h"
|
2020-11-28 14:52:46 +01:00
|
|
|
#include "core/http_server.h"
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
#include "rdn_application.h"
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-12-01 14:53:32 +01:00
|
|
|
#include "core/database_manager.h"
|
|
|
|
|
2020-12-01 15:01:02 +01:00
|
|
|
#include "database/db_init.h"
|
2020-12-01 14:47:24 +01:00
|
|
|
|
2020-12-08 16:22:18 +01:00
|
|
|
#include "core/settings.h"
|
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
#define MAIN_CLASS RDNApplication
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-12-08 16:22:18 +01:00
|
|
|
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("");
|
|
|
|
}
|
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
int main(int argc, char **argv) {
|
2020-12-01 23:37:10 +01:00
|
|
|
bool migrate = false;
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
const char *a = argv[i];
|
|
|
|
|
|
|
|
if (a[0] == 'm') {
|
|
|
|
migrate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 15:01:02 +01:00
|
|
|
initialize_database_backends();
|
2020-11-28 14:52:46 +01:00
|
|
|
|
2020-12-08 16:22:18 +01:00
|
|
|
Settings *settings = new Settings(true);
|
|
|
|
|
|
|
|
settings->parse_file("settings.json");
|
|
|
|
|
2020-11-28 14:52:46 +01:00
|
|
|
FileCache *file_cache = new FileCache(true);
|
|
|
|
file_cache->wwwroot = "./www";
|
|
|
|
file_cache->wwwroot_refresh_cache();
|
|
|
|
|
2020-12-01 14:47:24 +01:00
|
|
|
DatabaseManager *dbm = new DatabaseManager();
|
2020-12-01 18:29:41 +01:00
|
|
|
|
2020-12-08 16:22:18 +01:00
|
|
|
create_databases();
|
2020-12-01 14:47:24 +01:00
|
|
|
|
2020-11-28 14:52:46 +01:00
|
|
|
Application *app = new MAIN_CLASS();
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-12-08 16:22:18 +01:00
|
|
|
app->load_settings();
|
2020-11-28 14:52:46 +01:00
|
|
|
app->setup_routes();
|
|
|
|
app->setup_middleware();
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
HTTPServer *server = new HTTPServer();
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
server->port = 8080;
|
|
|
|
server->initialize();
|
2020-12-01 23:37:10 +01:00
|
|
|
|
|
|
|
if (!migrate) {
|
|
|
|
server->main_loop();
|
|
|
|
} else {
|
2020-12-02 00:43:46 +01:00
|
|
|
printf("Running migrations.\n");
|
2020-12-01 23:37:10 +01:00
|
|
|
app->migrate();
|
|
|
|
}
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
delete server;
|
2020-11-28 14:52:46 +01:00
|
|
|
delete app;
|
2020-12-01 14:47:24 +01:00
|
|
|
delete dbm;
|
2020-11-28 14:52:46 +01:00
|
|
|
delete file_cache;
|
2020-12-08 16:22:18 +01:00
|
|
|
delete settings;
|
2020-11-24 15:41:18 +01:00
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
return 0;
|
|
|
|
}
|