#include #include #include #include #include "globals.h" #include "config.h" static void add_cors_headers(const drogon::HttpRequestPtr &requestPtr, const drogon::HttpResponsePtr &responsePtr) { responsePtr->addHeader("Access-Control-Allow-Origin", "*"); } static void terminate(int signum) { LOG_INFO << "Terminating Server (" << signum << ")"; sqlite3_close(globals::db); quick_exit(signum); } /*static void test() { LOG_DEBUG << "LOOP"; }*/ int main(int argc, char** argv) { signal(SIGINT, terminate); signal(SIGABRT, terminate); signal(SIGTERM, terminate); const char* config_file_name = "config.json"; if(argc == 2) { config_file_name = argv[1]; } //Load config file drogon::app().loadConfigFile(config_file_name); const char* db_name = drogon::app().instance().getCustomConfig()["db_name"].asCString(); /* Open database */ int rc = sqlite3_open(db_name, &globals::db); if(rc) { LOG_FATAL << "Can't open database: " << sqlite3_errmsg(globals::db); return 1; } if(helpers::migrate_sql()) { terminate(1); } drogon::app().registerPostHandlingAdvice(add_cors_headers); drogon::app().instance().setCustom404Page(drogon::HttpResponse::newFileResponse("./static/index.html", "", drogon::CT_TEXT_HTML)); //drogon::app().getLoop()->runEvery(1, &test); //Run HTTP framework,the method will block in the internal event loop LOG_INFO << "Starting Emgauwa Core (" << config::version << ")"; drogon::app().run(); return 0; }