This commit is contained in:
chatlanin 2024-07-18 11:53:40 +03:00
parent 9720c479dd
commit 4e1d988480
2 changed files with 13 additions and 11 deletions

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <format>
#include "httplib.h" #include "httplib.h"
#include "hack/logger/logger.hpp" #include "hack/logger/logger.hpp"
@ -84,7 +85,7 @@ namespace trs
{ {
res.set_header("Access-Control-Allow-Origin", "*"); res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Allow", "POST, HEAD, OPTIONS"); 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"); res.set_header("Access-Control-Allow-Methods", "OPTIONS, HEAD, POST");
}); });
} }
@ -111,8 +112,7 @@ namespace trs
ex.service(m_service_name); ex.service(m_service_name);
if (m_log_to_console) if (m_log_to_console)
ex.log(); ex.log();
auto query = PGXX().prepare(var::LOGGER, ex.convert_to_json()); auto r = PGXX().execute(var::LOGGER, var::LOGGER, ex.convert_to_json());
auto r = PGXX().execute(var::LOGGER, query);
if (m_log_to_console) if (m_log_to_console)
hack::error()(r); hack::error()(r);
} }
@ -135,25 +135,25 @@ namespace trs
auto post(std::string func_name, JSON&& data) auto post(std::string func_name, JSON&& data)
{ {
httplib::Headers headers = { httplib::Headers headers = {
{ "TRS-server-token", m_token }, { var::HEADER_TOKEN, m_token },
{ "TRS-server-function", func_name }, { var::HEADER_FUNCTION, func_name },
{ "Content-Type", "application/json" }, { "Content-Type", var::HEADER_FLAG_JSON },
{ "Cookie", "unione_lang=ru" } { "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) auto post(std::string func_name, JSON& data)
{ {
httplib::Headers headers = { httplib::Headers headers = {
{ "TRS-server-token", m_token }, { var::HEADER_TOKEN, m_token },
{ "TRS-server-function", func_name }, { var::HEADER_FUNCTION, func_name },
{ "Content-Type", "application/json" }, { "Content-Type", var::HEADER_FLAG_JSON },
{ "Cookie", "unione_lang=ru" } { "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: private:

View File

@ -12,6 +12,8 @@ namespace trs::var
inline const std::string NO_VALID_DATA = "no valid data"; inline const std::string NO_VALID_DATA = "no valid data";
inline const std::string EXECUTE_ERROR = "execute error"; inline const std::string EXECUTE_ERROR = "execute error";
inline const std::string HEADER_FLAG_JSON = "application/json"; 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"; inline const std::string LOGGER = "logger";
} }