#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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 sinks; auto stdout_sink = spdlog::sinks::stdout_sink_mt::instance(); auto color_sink = std::make_shared( stdout_sink ); sinks.push_back(color_sink); sinks.push_back(std::make_shared("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; }