add app path config.
All checks were successful
Deploy / Build (push) Successful in 6m56s

This commit is contained in:
amass 2024-12-01 20:01:13 +08:00
parent 34253a4bf6
commit 03c7a564a1
10 changed files with 31 additions and 41 deletions

View File

@ -37,15 +37,24 @@ jobs:
cat notify.tpl | envsubst | jq -sR . | xargs -0 -I {} curl -H "Content-Type: application/json" -X POST -d '{"type":"text","msg":{} }' https://amass.fun/notify
- run: resources/build.sh build
- run: resources/build.sh lvgl
- name: Copy app wt resources to server
- name: copy wt resources to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ vars.YUYUN_SERVER }}
username: ${{ vars.YUYUN_USER }}
password: ${{ secrets.SERVER_ROOT_PASSWORD }}
overwrite: true
source: "resources/*.css,resources/*.xml"
source: "resources/*.css"
target: /root/Server/amass_blog
- name: copy wt app to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ vars.YUYUN_SERVER }}
username: ${{ vars.YUYUN_USER }}
password: ${{ secrets.SERVER_ROOT_PASSWORD }}
overwrite: true
source: "resources/*.xml"
target: /root/Server
- name: Copy lvgl to server
uses: appleboy/scp-action@v0.1.7
with:

View File

@ -29,11 +29,11 @@ public:
BUILD_SETTING(uint16_t, Port, 8081);
BUILD_SETTING(uint16_t, WtPort, 8082);
BUILD_SETTING(uint32_t, Threads, std::thread::hardware_concurrency());
BUILD_SETTING(std::string, DocumentRoot, ".");
BUILD_SETTING(std::string, ApplicationRoot, "."); // 内部配置文件,不应被外部访问
BUILD_SETTING(std::string, DocumentRoot, "."); // 外部可访问的公共文件
BUILD_SETTING(std::string, HomeAssistantAccessToken, "");
BUILD_SETTING(std::string, Live2dModelsRoot, "./live2d");
INITIALIZE_FIELDS(Server, Port, Threads, DocumentRoot);
INITIALIZE_FIELDS(Server, Port, Threads, ApplicationRoot, DocumentRoot);
Application(const std::string &path);
boost::asio::io_context &ioContext();
int exec();

View File

@ -3,12 +3,13 @@
#include "HttpSession.h"
#include "ServiceLogic.h"
#include <boost/url/url_view.hpp>
#include <format>
Live2dBackend::Live2dBackend() {
using namespace Amass;
auto application = Singleton<Application>::instance();
application->insertUrl("/api/v1/live2d/{path*}", [this, live2dModelsRoot{application->getLive2dModelsRoot()}](
HttpSession &session, const Application::Request &request,
m_live2dModelsRoot = std::format("{}/resources/live2d", application->getDocumentRoot());
application->insertUrl("/api/v1/live2d/{path*}", [this](HttpSession &session, const Application::Request &request,
const boost::urls::matches &matches) {
using namespace boost::beast;
boost::urls::url_view view(request.target());
@ -18,7 +19,7 @@ Live2dBackend::Live2dBackend() {
session.reply(ServiceLogic::badRequest(request, "Illegal request-target"));
return;
}
std::string path = ResponseUtility::pathCat(live2dModelsRoot, matches["path"]);
std::string path = ResponseUtility::pathCat(m_live2dModelsRoot, matches["path"]);
if (target.back() == '/') path.append("index.html");
if (std::filesystem::is_directory(path)) path.append("/index.html");
boost::beast::error_code ec;

View File

@ -1,9 +1,13 @@
#ifndef __LIVE2DBACKEND_H__
#define __LIVE2DBACKEND_H__
#include <string>
class Live2dBackend {
public:
Live2dBackend();
private:
std::string m_live2dModelsRoot;
};
#endif // __LIVE2DBACKEND_H__

View File

@ -64,7 +64,7 @@ int main(int argc, char const *argv[]) {
std::exit(102);
}
BOOST_ASSERT_MSG(!application->getServer().empty(), "server.empty() == true");
Database::initialize(std::format("{}/database.sqlite", application->getDocumentRoot()));
Database::initialize(std::format("{}/database.sqlite", application->getApplicationRoot()));
auto address = boost::asio::ip::make_address(application->getServer());
auto listener =
std::make_shared<Listener>(application->ioContext(), boost::asio::ip::tcp::endpoint{address, application->getPort()});
@ -96,7 +96,7 @@ int main(int argc, char const *argv[]) {
auto udpServer = std::make_shared<UdpServer>(application->ioContext());
auto mediaServer = std::make_shared<MediaServer>(554, false);
auto webApp = Singleton<WebToolkit::Server>::instance<Construct>(application->getWtPort(), application->getDocumentRoot());
auto webApp = Singleton<WebToolkit::Server>::instance<Construct>(application->getWtPort(), application->getApplicationRoot(), application->getDocumentRoot());
using namespace boost::asio::ip;
auto proxyAddress = make_address(application->getServer());

View File

@ -117,15 +117,15 @@ void Application::handlePathChange(const std::string &path) {
}
}
Server::Server(uint16_t port, const std::string &documentRoot) {
Server::Server(uint16_t port, const std::string &applicationRoot, const std::string &documentRoot) {
try {
std::vector<std::string> args;
args.push_back(std::format("--docroot={};/resources", documentRoot));
args.push_back(std::format("--approot={}/resources", documentRoot));
args.push_back(std::format("--approot={}/resources", applicationRoot));
args.push_back(std::format("--http-listen=127.0.0.1:{}", port));
initializeAuthenticationService();
m_server = std::make_unique<Wt::WServer>(std::format("{}/resources", documentRoot), args);
m_server = std::make_unique<Wt::WServer>(std::format("{}/resources", applicationRoot), args);
m_server->addEntryPoint(Wt::EntryPointType::Application,
std::bind(&Server::createApplication, this, std::placeholders::_1, false));
@ -133,7 +133,6 @@ Server::Server(uint16_t port, const std::string &documentRoot) {
std::bind(&Server::createApplication, this, std::placeholders::_1, true), "/wt/app.js");
m_server->addResource(std::make_shared<AuthenticationResource>(), "/auth");
m_server->addResource(std::make_shared<PlaintextResource>(), "/plaintext");
m_server->addResource(std::make_shared<DbResource>(std::format("{}/database.sqlite", documentRoot)), "/db");
m_server->start();
} catch (const std::exception &e) {

View File

@ -51,7 +51,7 @@ public:
const Wt::Auth::PasswordService &passwordService();
protected:
Server(uint16_t port, const std::string &documentRoot);
Server(uint16_t port, const std::string &applicationRoot, const std::string &documentRoot);
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env, bool embedded);
private:

View File

@ -27,23 +27,6 @@ void PlaintextResource::handleRequest(const Wt::Http::Request &request, Wt::Http
response.out() << "Hello, World!";
}
DbResource::DbResource(const std::string &db) {
if (!m_dbStruct) {
m_dbStruct = new DbStruct(db);
}
}
void DbResource::handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
response.setMimeType("application/json");
response.addHeader("Server", "Wt");
Wt::Dbo::Transaction transaction(m_dbStruct->session);
Wt::Dbo::ptr<World> entry = m_dbStruct->session.load<World>(m_dbStruct->rand());
Wt::Dbo::JsonSerializer writer(response.out());
writer.serialize(entry);
}
int DbStruct::rand() {
return distribution(rng);
}

View File

@ -55,10 +55,4 @@ public:
void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) final;
};
class DbResource : public Wt::WResource {
public:
DbResource(const std::string &db);
void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) final;
};
#endif // __RESTFUL_H__

View File

@ -25,7 +25,7 @@ function build() {
# reset
# pkill -9 HttpServer
# cp -r /opt/Libraries/wt-4.11.1/share/Wt/* ./build
# cp -r resources/* build/resources/
# cp -r resources/themes resources/*.css build/resources/
if [ ! -f "${build_path}/CMakeCache.txt" ]; then
cmake_scan