diff --git a/src/trs/trs.hpp b/src/trs/trs.hpp index ff1bab7..2173be2 100644 --- a/src/trs/trs.hpp +++ b/src/trs/trs.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "httplib.h" #include "hack/logger/logger.hpp" @@ -84,7 +85,7 @@ namespace trs { res.set_header("Access-Control-Allow-Origin", "*"); res.set_header("Allow", "POST, HEAD, OPTIONS"); - res.set_header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept, Origin, Authorization, TRS-server-function, TRS-server-token"); + res.set_header( "Access-Control-Allow-Headers", std::format("X-Requested-With, Content-Type, Accept, Origin, Authorization, {}, {}", var::HEADER_TOKEN, var::HEADER_FUNCTION).c_str()); res.set_header("Access-Control-Allow-Methods", "OPTIONS, HEAD, POST"); }); } @@ -111,8 +112,7 @@ namespace trs ex.service(m_service_name); if (m_log_to_console) ex.log(); - auto query = PGXX().prepare(var::LOGGER, ex.convert_to_json()); - auto r = PGXX().execute(var::LOGGER, query); + auto r = PGXX().execute(var::LOGGER, var::LOGGER, ex.convert_to_json()); if (m_log_to_console) hack::error()(r); } @@ -135,25 +135,25 @@ namespace trs auto post(std::string func_name, JSON&& data) { httplib::Headers headers = { - { "TRS-server-token", m_token }, - { "TRS-server-function", func_name }, - { "Content-Type", "application/json" }, + { var::HEADER_TOKEN, m_token }, + { var::HEADER_FUNCTION, func_name }, + { "Content-Type", var::HEADER_FLAG_JSON }, { "Cookie", "unione_lang=ru" } }; - return m_cli.Post("/", headers, data.dump(),"application/json" ); + return m_cli.Post("/", headers, data.dump(), var::HEADER_FLAG_JSON ); } auto post(std::string func_name, JSON& data) { httplib::Headers headers = { - { "TRS-server-token", m_token }, - { "TRS-server-function", func_name }, - { "Content-Type", "application/json" }, + { var::HEADER_TOKEN, m_token }, + { var::HEADER_FUNCTION, func_name }, + { "Content-Type", var::HEADER_FLAG_JSON }, { "Cookie", "unione_lang=ru" } }; - return m_cli.Post("/", headers, data.dump(),"application/json" ); + return m_cli.Post("/", headers, data.dump(), var::HEADER_FLAG_JSON ); } private: diff --git a/src/trs/utils/var.hpp b/src/trs/utils/var.hpp index 75bc1c0..89e9f13 100644 --- a/src/trs/utils/var.hpp +++ b/src/trs/utils/var.hpp @@ -12,6 +12,8 @@ namespace trs::var inline const std::string NO_VALID_DATA = "no valid data"; inline const std::string EXECUTE_ERROR = "execute error"; inline const std::string HEADER_FLAG_JSON = "application/json"; + inline const std::string HEADER_TOKEN = "TRS-server-token"; + inline const std::string HEADER_FUNCTION = "TRS-server-function"; inline const std::string LOGGER = "logger"; }