Files
App/src/server/api_settings_routes.cpp
HiepLM 77ea3cc361
Some checks failed
Test / test (push) Has been cancelled
Thêm phần 5. Monitoring và 6. System
2026-06-25 16:00:18 +07:00

36 lines
914 B
C++

#include "server/api_server.hpp"
#include "util/http_util.hpp"
namespace lm {
void ApiServer::registerSettingsRoutes(httplib::Server& svr)
{
svr.Get("/api/settings", [this](const httplib::Request&, httplib::Response& res) {
HttpUtil::addCors(res);
res.set_header("Content-Type", "application/json; charset=utf-8");
res.body = settings_.get().dump();
});
svr.Put("/api/settings", [this](const httplib::Request& req, httplib::Response& res) {
HttpUtil::addCors(res);
nlohmann::json body;
try
{
body = nlohmann::json::parse(req.body);
}
catch (...)
{
return HttpUtil::jsonError(res, 400, "invalid JSON");
}
std::string err;
if (!settings_.put(body, err))
return HttpUtil::jsonError(res, 400, err);
res.set_header("Content-Type", "application/json; charset=utf-8");
res.body = settings_.get().dump();
});
}
} // namespace lm