Older/WebApplication/WebApplication.cpp

55 lines
2.1 KiB
C++
Raw Normal View History

2024-10-30 23:59:59 +08:00
#include "WebApplication.h"
2024-11-01 19:05:20 +08:00
#include "BlogApplication.h"
2024-10-30 23:59:59 +08:00
#include "BoostLog.h"
#include "Hello.h"
2024-11-01 19:05:20 +08:00
#include "Restful.h"
2024-10-31 19:40:29 +08:00
#include "Session.h"
2024-11-01 19:05:20 +08:00
#include "model/BlogSession.h"
#include <Wt/Dbo/SqlConnectionPool.h>
2024-10-30 23:59:59 +08:00
#include <Wt/WServer.h>
static std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env) {
return std::make_unique<Hello>(env, false);
}
2024-11-10 18:33:39 +08:00
std::unique_ptr<Wt::WApplication> createBlogApplication(const Wt::WEnvironment &env,
Wt::Dbo::SqlConnectionPool *blogDb) {
2024-11-01 19:05:20 +08:00
return std::make_unique<BlogApplication>(env, *blogDb);
}
2024-10-30 23:59:59 +08:00
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;
2024-11-02 00:30:14 +08:00
args.push_back("--approot=./build");
2024-10-30 23:59:59 +08:00
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);
2024-11-01 19:05:20 +08:00
m_server->addEntryPoint(Wt::EntryPointType::Application, createApplication, "/hello");
2024-11-02 00:30:14 +08:00
BlogSession::configureAuth();
2024-11-07 18:21:04 +08:00
m_blogSqlConnectionPool = BlogSession::createConnectionPool(m_server->appRoot() + "database.sqlite");
2024-11-10 18:33:39 +08:00
m_server->addEntryPoint(Wt::EntryPointType::Application,
std::bind(&createBlogApplication, std::placeholders::_1, m_blogSqlConnectionPool.get()),
2024-11-07 18:21:04 +08:00
"/blog");
2024-10-30 23:59:59 +08:00
m_server->addEntryPoint(Wt::EntryPointType::WidgetSet, createWidgetSet, "/gui/hello.js");
2024-10-31 19:40:29 +08:00
Session::configureAuth();
2024-11-01 19:05:20 +08:00
m_server->addResource(std::make_shared<JsonResource>(), "/json");
m_server->addResource(std::make_shared<PlaintextResource>(), "/plaintext");
m_server->addResource(std::make_shared<DbResource>("database.sqlite"), "/db");
2024-10-30 23:59:59 +08:00
2024-11-10 18:33:39 +08:00
m_server->start();
2024-10-30 23:59:59 +08:00
} catch (const std::exception &e) {
LOG(error) << e.what();
}
}
WebApplication::~WebApplication() {
}
2024-11-10 18:33:39 +08:00