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
|
|
|
#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-31 02:13:01 +02:00
|
|
|
#include "app/mourne_user_controller.h"
|
2021-11-14 22:54:29 +01:00
|
|
|
#include "app/mourne_user_model.h"
|
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
|
|
|
|
2021-10-30 22:48:02 +02:00
|
|
|
//todo init these in the module automatically
|
2021-11-14 22:54:29 +01:00
|
|
|
MourneUserController *user_controller = new MourneUserController();
|
|
|
|
MourneUserModel *user_model = new MourneUserModel();
|
2021-10-30 22:48:02 +02:00
|
|
|
//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-11-14 13:59:02 +01:00
|
|
|
MourneApplication *app = new MourneApplication();
|
2021-10-30 22:48:02 +02:00
|
|
|
|
2021-10-30 19:01:52 +02:00
|
|
|
app->load_settings();
|
|
|
|
app->setup_routes();
|
|
|
|
app->setup_middleware();
|
|
|
|
|
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) {
|
|
|
|
printf("Initialized!\n");
|
2021-11-14 02:28:56 +01:00
|
|
|
session_manager->load_sessions();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
session_manager->migrate();
|
|
|
|
user_model->migrate();
|
|
|
|
|
2021-11-14 02:38:29 +01:00
|
|
|
if (Platform::get_singleton()->arg_parser.has_arg("-u")) {
|
|
|
|
printf("Creating test users.\n");
|
|
|
|
user_model->create_test_users();
|
|
|
|
}
|
|
|
|
|
2021-10-30 19:01:52 +02:00
|
|
|
app->migrate();
|
2021-11-14 13:59:02 +01:00
|
|
|
|
|
|
|
if (Platform::get_singleton()->arg_parser.has_arg("-d")) {
|
|
|
|
printf("Adding data.\n");
|
|
|
|
app->add_default_data();
|
|
|
|
}
|
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 user_controller;
|
|
|
|
delete user_model;
|
|
|
|
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;
|
|
|
|
}
|