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"
|
2022-01-09 17:05:04 +01:00
|
|
|
#include "core/http/web_root.h"
|
2021-10-30 19:01:52 +02:00
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
#include "app/mourne_root.h"
|
2021-10-30 19:01:52 +02:00
|
|
|
|
|
|
|
#include "database/db_init.h"
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
#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
|
|
|
|
2022-01-09 17:05:04 +01: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
|
|
|
|
2021-11-14 02:28:56 +01:00
|
|
|
#include "modules/users/user.h"
|
2021-10-30 19:01:52 +02:00
|
|
|
|
2021-11-14 02:28:56 +01: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");
|
|
|
|
}
|
|
|
|
|
2021-11-14 02:28:56 +01:00
|
|
|
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
|
|
|
|
2021-11-14 02:28:56 +01: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
|
|
|
|
2022-01-09 17:05:04 +01: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();
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
DrogonWebServer *app = new DrogonWebServer();
|
|
|
|
MourneRoot *app_root = new MourneRoot();
|
|
|
|
app_root->setup();
|
2021-10-30 19:01:52 +02:00
|
|
|
|
2021-11-14 02:38:29 +01:00
|
|
|
bool migrate = Platform::get_singleton()->arg_parser.has_arg("-m");
|
2021-10-30 19:01:52 +02:00
|
|
|
|
|
|
|
if (!migrate) {
|
2022-01-09 17:05:04 +01:00
|
|
|
settings->load();
|
2021-11-14 02:28:56 +01:00
|
|
|
session_manager->load_sessions();
|
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
printf("Initialized!\n");
|
2021-11-14 02:28:56 +01:00
|
|
|
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
|
|
|
|
2022-01-09 17:05:04 +01:00
|
|
|
settings->migrate();
|
2021-10-30 22:48:02 +02:00
|
|
|
session_manager->migrate();
|
2022-01-09 17:05:04 +01:00
|
|
|
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
|
|
|
|
2021-11-14 02:28:56 +01:00
|
|
|
PlatformInitializer::free_all();
|
|
|
|
|
2021-10-30 19:01:52 +02:00
|
|
|
return 0;
|
|
|
|
}
|