2019-07-12 19:05:56 +00:00
|
|
|
#include <drogon/drogon.h>
|
|
|
|
#include <sqlite3.h>
|
|
|
|
|
2019-07-22 20:06:13 +00:00
|
|
|
#include <models/controller_dbo.h>
|
2019-07-19 09:41:39 +00:00
|
|
|
#include <csignal>
|
2019-07-12 19:05:56 +00:00
|
|
|
|
|
|
|
#include "globals.h"
|
2019-08-22 19:38:23 +00:00
|
|
|
#include "config.h"
|
2019-07-12 19:05:56 +00:00
|
|
|
|
2019-09-08 21:24:31 +00:00
|
|
|
static void
|
|
|
|
add_cors_headers(const drogon::HttpRequestPtr &requestPtr, const drogon::HttpResponsePtr &responsePtr)
|
|
|
|
{
|
|
|
|
responsePtr->addHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
}
|
|
|
|
|
2019-07-19 12:42:36 +00:00
|
|
|
static void
|
|
|
|
terminate(int signum)
|
|
|
|
{
|
|
|
|
LOG_INFO << "Terminating Server (" << signum << ")";
|
|
|
|
|
|
|
|
sqlite3_close(globals::db);
|
|
|
|
|
|
|
|
quick_exit(signum);
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:41:39 +00:00
|
|
|
/*static void test()
|
|
|
|
{
|
|
|
|
LOG_DEBUG << "LOOP";
|
|
|
|
}*/
|
2019-07-12 19:05:56 +00:00
|
|
|
|
2019-07-19 12:42:36 +00:00
|
|
|
int
|
|
|
|
main()
|
2019-07-19 09:41:39 +00:00
|
|
|
{
|
2019-07-19 12:42:36 +00:00
|
|
|
signal(SIGINT, terminate);
|
|
|
|
signal(SIGABRT, terminate);
|
|
|
|
signal(SIGTERM, terminate);
|
|
|
|
signal(SIGKILL, terminate);
|
|
|
|
|
2019-07-12 19:05:56 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Open database */
|
2019-09-08 12:28:50 +00:00
|
|
|
rc = sqlite3_open("core.sqlite", &globals::db);
|
2019-07-12 19:05:56 +00:00
|
|
|
|
|
|
|
if( rc ) {
|
2019-08-06 22:11:48 +00:00
|
|
|
LOG_FATAL << "Can't open database: " << sqlite3_errmsg(globals::db);
|
2019-07-12 19:05:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Load config file
|
2019-08-06 22:01:01 +00:00
|
|
|
drogon::app().loadConfigFile("config.json");
|
2019-07-19 09:41:39 +00:00
|
|
|
|
2019-09-08 21:24:31 +00:00
|
|
|
drogon::app().registerPostHandlingAdvice(add_cors_headers);
|
2019-09-16 23:55:29 +00:00
|
|
|
drogon::app().instance().setCustom404Page(drogon::HttpResponse::newFileResponse("./index.html", "", drogon::CT_TEXT_HTML));
|
2019-09-08 21:24:31 +00:00
|
|
|
|
2019-07-19 09:41:39 +00:00
|
|
|
//drogon::app().getLoop()->runEvery(1, &test);
|
|
|
|
|
2019-07-12 19:05:56 +00:00
|
|
|
//Run HTTP framework,the method will block in the internal event loop
|
2019-08-22 19:38:23 +00:00
|
|
|
|
|
|
|
LOG_INFO << "Starting Emgauwa Core (" << config::version << ")";
|
|
|
|
|
2019-07-12 19:05:56 +00:00
|
|
|
drogon::app().run();
|
|
|
|
return 0;
|
|
|
|
}
|