mourne_rcpp_fw/main.cpp

106 lines
2.2 KiB
C++
Raw Normal View History

2021-10-30 19:01:52 +02:00
#include <string.h>
#include <iostream>
#include <string>
#include "core/bry_http/http_server.h"
2021-10-30 22:48:02 +02:00
#include "core/file_cache.h"
#include "core/http/web_application.h"
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
#include "app/mourne_application.h"
2021-10-30 19:01:52 +02:00
#include "database/db_init.h"
#include "core/settings.h"
2021-10-30 22:48:02 +02:00
#include "core/http/session_manager.h"
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
#define MAIN_CLASS MourneApplication
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
#include "modules/drogon/web_application.h"
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
//Backends
#include "backends/hash_hashlib/setup.h"
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
#include "modules/users/user.h"
#include "app/mourne_user_controller.h"
2021-10-30 22:48:02 +02:00
#include "modules/users/user_model.h"
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
#include "core/database/database_manager.h"
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
void initialize_backends() {
initialize_database_backends();
backend_hash_hashlib_install_providers();
}
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
void create_databases() {
DatabaseManager *dbm = DatabaseManager::get_singleton();
2021-10-30 19:01:52 +02:00
uint32_t index = dbm->create_database("sqlite");
Database *db = dbm->databases[index];
db->connect("database.sqlite");
}
int main(int argc, char **argv) {
2021-10-30 22:48:02 +02:00
initialize_backends();
2021-10-30 19:01:52 +02:00
bool migrate = false;
for (int i = 1; i < argc; ++i) {
const char *a = argv[i];
if (a[0] == 'm') {
migrate = true;
}
}
2021-10-30 22:48:02 +02:00
::SessionManager *session_manager = new ::SessionManager();
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
//todo init these in the module automatically
UserController *user_controller = new MourneUserController();
2021-10-30 22:48:02 +02:00
UserModel *user_model = new UserModel();
//user_manager->set_path("./users/");
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
Settings *settings = new Settings(true);
2021-10-30 23:55:53 +02:00
//settings->parse_file("settings.json");
2021-10-30 19:01:52 +02:00
FileCache *file_cache = new FileCache(true);
2021-10-30 22:48:02 +02:00
file_cache->wwwroot = "./www";
2021-10-30 19:01:52 +02:00
file_cache->wwwroot_refresh_cache();
DatabaseManager *dbm = new DatabaseManager();
create_databases();
2021-10-30 22:48:02 +02:00
DWebApplication *app = new MAIN_CLASS();
session_manager->load_sessions();
2021-10-30 19:01:52 +02:00
app->load_settings();
app->setup_routes();
app->setup_middleware();
2021-10-30 22:48:02 +02:00
app->add_listener("127.0.0.1", 8080);
LOG_INFO << "Server running on 127.0.0.1:8080";
2021-10-30 19:01:52 +02:00
if (!migrate) {
printf("Initialized!\n");
2021-10-30 22:48:02 +02:00
app->run();
2021-10-30 19:01:52 +02:00
} else {
printf("Running migrations.\n");
2021-10-30 22:48:02 +02:00
session_manager->migrate();
user_model->migrate();
2021-10-30 19:01:52 +02:00
app->migrate();
}
delete app;
delete dbm;
delete file_cache;
delete settings;
2021-10-30 22:48:02 +02:00
delete user_controller;
delete user_model;
delete session_manager;
2021-10-30 19:01:52 +02:00
return 0;
}