mourne_rcpp_fw/main.cpp

61 lines
1.4 KiB
C++
Raw Normal View History

2021-10-30 19:01:52 +02:00
#include "app/mourne_root.h"
#include "core/os/platform.h"
2022-02-05 23:02:06 +01:00
#include "core/settings/settings.h"
#include "database/database_manager.h"
#include "database_modules/db_settings/db_settings.h"
#include "web/file_cache.h"
#include "web/http/session_manager.h"
#include "web_backends/drogon/drogon_web_server.h"
2022-02-05 23:02:06 +01:00
#include "rcpp_framework.h"
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) {
2022-02-05 23:02:06 +01:00
RCPPFramework::create_and_init(argc, argv, envp);
RCPPFramework::get_singleton()->www_root = "./www";
2021-10-30 19:01:52 +02:00
create_databases();
DrogonWebServer *app = new DrogonWebServer();
2022-02-05 23:02:06 +01:00
RCPPFramework::get_singleton()->manage_object(app);
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) {
2022-02-05 23:02:06 +01:00
RCPPFramework::get_singleton()->load();
2022-02-05 23:02:06 +01:00
RLOG_MSG("Initialized!\n");
app->add_listener("127.0.0.1", 8080);
2022-02-05 23:02:06 +01:00
RLOG_MSG("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 {
2022-02-05 23:02:06 +01:00
RLOG_MSG("Running migrations.\n");
2021-10-30 22:48:02 +02:00
2022-02-05 23:02:06 +01:00
RCPPFramework::get_singleton()->migrate();
bool seed_db = Platform::get_singleton()->arg_parser.has_arg("-s");
2021-10-30 19:01:52 +02:00
2022-02-05 23:02:06 +01:00
if (seed_db) {
RLOG_MSG("Seeding database.\n");
}
app_root->migrate(true, seed_db);
}
2021-10-30 19:01:52 +02:00
2022-02-05 23:02:06 +01:00
RCPPFramework::destroy();
2021-10-30 19:01:52 +02:00
return 0;
}