mourne_rcpp_fw/main.cpp

95 lines
2.0 KiB
C++
Raw Normal View History

2021-10-30 19:01:52 +02:00
#include <string.h>
#include <iostream>
#include <string>
2021-10-30 22:48:02 +02:00
#include "core/file_cache.h"
#include "core/http/web_root.h"
2021-10-30 19:01:52 +02:00
#include "app/mourne_root.h"
2021-10-30 19:01:52 +02:00
#include "database/db_init.h"
#include "core/settings/settings.h"
#include "core/settings/db_settings.h"
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
#include "core/http/session_manager.h"
2021-10-30 19:01:52 +02:00
#include "modules/drogon/drogon_web_server.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
#include "modules/users/user.h"
2021-10-30 19:01:52 +02:00
#include "core/os/platform.h"
#include "platform/platform_initializer.h"
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, char **envp) {
PlatformInitializer::allocate_all();
PlatformInitializer::arg_setup(argc, argv, envp);
2021-10-30 19:01:52 +02:00
initialize_backends();
2021-10-30 19:01:52 +02:00
2021-10-30 22:48:02 +02:00
::SessionManager *session_manager = new ::SessionManager();
2021-10-30 19:01:52 +02:00
DBSettings *settings = new DBSettings(true);
// 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();
DrogonWebServer *app = new DrogonWebServer();
MourneRoot *app_root = new MourneRoot();
app_root->setup();
2021-10-30 19:01:52 +02:00
2022-01-09 17:09:47 +01:00
app->set_root(app_root);
bool migrate = Platform::get_singleton()->arg_parser.has_arg("-m");
2021-10-30 19:01:52 +02:00
if (!migrate) {
settings->load();
session_manager->load_sessions();
printf("Initialized!\n");
app->add_listener("127.0.0.1", 8080);
LOG_INFO << "Server running on 127.0.0.1:8080";
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
settings->migrate();
2021-10-30 22:48:02 +02:00
session_manager->migrate();
app_root->migrate();
2021-10-30 19:01:52 +02:00
}
delete app;
delete dbm;
delete file_cache;
delete settings;
2021-10-30 22:48:02 +02:00
delete session_manager;
2021-10-30 19:01:52 +02:00
PlatformInitializer::free_all();
2021-10-30 19:01:52 +02:00
return 0;
}