This commit is contained in:
amass 2024-01-02 22:48:00 +08:00
parent 184559e223
commit 9820550844

View File

@ -26,6 +26,7 @@ SharedState::SharedState(boost::asio::io_context &ioContext, std::string doc_roo
if (ec == boost::beast::errc::no_such_file_or_directory) {
std::ostringstream oss;
oss << "The resource '" << target << "' was not found.";
LOG(error) << oss.str();
session.errorReply(request, http::status::not_found, oss.str());
return;
} else if (ec) {
@ -50,11 +51,27 @@ SharedState::SharedState(boost::asio::io_context &ioContext, std::string doc_roo
m_router->insert("/api/v1/tasklist",[this](HttpSession &session, const Request &request, const boost::urls::matches &matches) {
using namespace boost::beast;
http::response<boost::beast::http::string_body> s;
http::response<boost::beast::http::string_body> s{boost::beast::http::status::ok, request.version()};
s.set(http::field::server, BOOST_BEAST_VERSION_STRING);
s.set(http::field::content_type, "text/markdown;charset=UTF-8");
s.set(http::field::content_type, "application/json;charset=UTF-8");
s.keep_alive(request.keep_alive());
s.body() = "{}";
s.body() = "[]";
s.prepare_payload();
session.reply(std::move(s));
});
m_router->insert("/api/v1/task/add",[this](HttpSession &session, const Request &request, const boost::urls::matches &matches) {
using namespace boost::beast;
LOG(info)<<"add task: "<<request.body();
boost::json::object reply;
reply["status"] = 0;
http::response<boost::beast::http::string_body> s{boost::beast::http::status::ok, request.version()};
s.set(http::field::server, BOOST_BEAST_VERSION_STRING);
s.set(http::field::content_type, "application/json;charset=UTF-8");
s.keep_alive(request.keep_alive());
s.body() = boost::json::serialize(reply);
s.prepare_payload();
session.reply(std::move(s));
});