From 9820550844e8de133ce3c32f33471c182757f223 Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Tue, 2 Jan 2024 22:48:00 +0800 Subject: [PATCH] add log. --- Server/SharedState.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Server/SharedState.cpp b/Server/SharedState.cpp index 33ac085..ffdff38 100644 --- a/Server/SharedState.cpp +++ b/Server/SharedState.cpp @@ -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 s; + http::response 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: "< 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)); });