84 lines
3.1 KiB
C++
84 lines
3.1 KiB
C++
#include <eedb/EEDB.hpp>
|
|
|
|
#include <eedb/WebSession.hpp>
|
|
#include <eedb/auth/PgUserAuth.hpp>
|
|
#include <eedb/auth/Services.hpp>
|
|
#include <eedb/db/config.hpp>
|
|
#include <eedb/db/connection.hpp>
|
|
#include <eedb/widgets/BootstrapTheme.hpp>
|
|
#include <eedb/widgets/DefaultAuthPage.hpp>
|
|
#include <eedb/widgets/DefaultHomePage.hpp>
|
|
#include <eedb/widgets/DefaultNavigationBar.hpp>
|
|
|
|
#include <Wt/WApplication.h>
|
|
#include <Wt/WContainerWidget.h>
|
|
#include <Wt/WServer.h>
|
|
#include <Wt/WText.h>
|
|
|
|
#include <sqlpp11/postgresql/exception.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
class ErrorWindow : public Wt::WApplication {
|
|
public:
|
|
ErrorWindow(const Wt::WEnvironment & env);
|
|
};
|
|
ErrorWindow::ErrorWindow(const Wt::WEnvironment & env) : Wt::WApplication(env) {
|
|
root()->addWidget(std::make_unique< Wt::WText >("error"));
|
|
}
|
|
|
|
std::unique_ptr< Wt::WApplication > createApplication(const Wt::WEnvironment & env) {
|
|
try {
|
|
using std::make_unique;
|
|
using std::move;
|
|
using std::unique_ptr;
|
|
|
|
auto dbConfig = make_unique< eedb::db::PgConfig >(env);
|
|
|
|
auto dbConnection = make_unique< eedb::db::PgConnection >(move(dbConfig));
|
|
auto session = unique_ptr< eedb::Session >(make_unique< eedb::WebSession >(move(dbConnection), env));
|
|
|
|
auto authPageFactory = [_session = session.get()]()->std::unique_ptr< eedb::AuthPage > {
|
|
auto userDatabase = make_unique< eedb::auth::PgUserAuth >(_session->db(), _session->enviroment());
|
|
auto services = eedb::auth::Services();
|
|
auto & login = _session->login();
|
|
|
|
return make_unique< eedb::DefaultAuthPage >(services, std::move(userDatabase), login);
|
|
};
|
|
|
|
auto homePageFactory = [_session = session.get()]()->std::unique_ptr< eedb::HomePage > {
|
|
auto navigationBar = std::make_unique< eedb::DefaultNavigationBar >();
|
|
return make_unique< eedb::DefaultHomePage >(*_session, std::move(navigationBar));
|
|
};
|
|
|
|
return make_unique< eedb::EEDB >(std::move(session), authPageFactory, homePageFactory);
|
|
} catch(const sqlpp::postgresql::broken_connection & e) {
|
|
std::cout << "sql exception: " << e.what();
|
|
return std::make_unique< ErrorWindow >(env);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char ** argv) {
|
|
std::vector<spdlog::sink_ptr> sinks;
|
|
auto stdout_sink = spdlog::sinks::stdout_sink_mt::instance();
|
|
auto color_sink = std::make_shared<spdlog::sinks::ansicolor_sink>( stdout_sink );
|
|
sinks.push_back(color_sink);
|
|
sinks.push_back(std::make_shared<spdlog::sinks::daily_file_sink_st>("logfile", 23, 59));
|
|
auto combined_logger = std::make_shared< spdlog::logger >("default", begin(sinks), end(sinks));
|
|
combined_logger->set_level( spdlog::level::trace );
|
|
|
|
spdlog::register_logger(combined_logger);
|
|
|
|
try {
|
|
Wt::WServer server(argc, argv, WTHTTP_CONFIGURATION);
|
|
server.addEntryPoint(Wt::EntryPointType::Application, createApplication);
|
|
eedb::auth::Services::configureAuth();
|
|
server.run();
|
|
} catch(Wt::WServer::Exception & e) {
|
|
std::cerr << e.what() << std::endl;
|
|
} catch(std::exception & e) {
|
|
std::cerr << "exception: " << e.what() << std::endl;
|
|
}
|
|
return 0;
|
|
}
|