46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#include "WebApplication.h"
|
|
#include "BoostLog.h"
|
|
#include "Hello.h"
|
|
#include "Session.h"
|
|
#include <Wt/WServer.h>
|
|
|
|
static std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env) {
|
|
return std::make_unique<Hello>(env, false);
|
|
}
|
|
|
|
static std::unique_ptr<Wt::WApplication> createWidgetSet(const Wt::WEnvironment &env) {
|
|
return std::make_unique<Hello>(env, true);
|
|
}
|
|
|
|
WebApplication::WebApplication() {
|
|
try {
|
|
std::vector<std::string> args;
|
|
args.push_back("--docroot=./build");
|
|
args.push_back("--http-listen=127.0.0.1:8855");
|
|
// --docroot=. --no-compression --http-listen 127.0.0.1:8855
|
|
m_server = std::make_unique<Wt::WServer>("./build", args);
|
|
m_server->addEntryPoint(Wt::EntryPointType::Application, createApplication);
|
|
m_server->addEntryPoint(Wt::EntryPointType::WidgetSet, createWidgetSet, "/gui/hello.js");
|
|
Session::configureAuth();
|
|
m_thread = std::thread(&WebApplication::run, this);
|
|
|
|
} catch (const std::exception &e) {
|
|
LOG(error) << e.what();
|
|
}
|
|
}
|
|
|
|
WebApplication::~WebApplication() {
|
|
if (m_thread.joinable()) {
|
|
m_thread.join();
|
|
}
|
|
}
|
|
|
|
void WebApplication::run() {
|
|
try {
|
|
|
|
m_server->run();
|
|
} catch (const std::exception &e) {
|
|
LOG(error) << e.what();
|
|
}
|
|
}
|