fix api error
This commit is contained in:
parent
19b43a3bba
commit
360b9351da
@ -29,7 +29,7 @@ namespace trs
|
||||
~server() = default;
|
||||
|
||||
public:
|
||||
void init(std::string service_name)
|
||||
void init(std::string service_name, std::string url = "/")
|
||||
{
|
||||
if (!PGXX().ready())
|
||||
{
|
||||
@ -38,13 +38,15 @@ namespace trs
|
||||
return;
|
||||
}
|
||||
|
||||
m_service_name = service_name;
|
||||
API_URL = url;
|
||||
|
||||
set_read_timeout(5, 0);
|
||||
set_write_timeout(5, 0);
|
||||
set_idle_interval(0, 1'000'000);
|
||||
set_payload_max_length(1024 * 1024 * 512); // 512MB
|
||||
set_CORS();
|
||||
set_post();
|
||||
m_service_name = service_name;
|
||||
}
|
||||
|
||||
void log_to_console(bool v) { m_log_to_console = v; }
|
||||
@ -78,28 +80,31 @@ namespace trs
|
||||
bool m_log_to_console { true };
|
||||
function_manager<transaction> m_function_manager;
|
||||
inspector<transaction> m_inspector;
|
||||
std::string API_URL { "/" };
|
||||
|
||||
|
||||
private:
|
||||
void set_CORS()
|
||||
{
|
||||
Options(R"(\*)", [](const auto& req, auto& res) { res.set_header("Allow", "POST, HEAD, OPTIONS"); });
|
||||
Options(var::API_URL, [](const auto& req, auto& res)
|
||||
Options(API_URL, [](const auto& req, auto& res)
|
||||
{
|
||||
res.set_header("Access-Control-Allow-Origin", "*");
|
||||
res.set_header("Allow", "POST, HEAD, OPTIONS");
|
||||
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-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");
|
||||
});
|
||||
}
|
||||
|
||||
void set_post()
|
||||
{
|
||||
Post(var::API_URL, [&](const httplib::Request& req, httplib::Response& res) {
|
||||
Post(API_URL, [&](const httplib::Request& req, httplib::Response& res) {
|
||||
res.set_header("Access-Control-Allow-Origin", "*");
|
||||
res.set_header("Access-Control-Allow-Headers", "*");
|
||||
res.set_header("Access-Control-Allow-Methods", "POST");
|
||||
res.set_header("Access-Control-Allow-Credentials", "false");
|
||||
|
||||
hack::log()(API_URL);
|
||||
transaction tr;
|
||||
|
||||
try
|
||||
|
@ -6,7 +6,6 @@ namespace trs::var
|
||||
{
|
||||
inline const int PORT = 5000;
|
||||
inline const std::string HOST = "0.0.0.0";
|
||||
inline const std::string API_URL = "/";
|
||||
|
||||
inline const std::string ALIEN_SYSTEM_ERROR = "is alien system error it can be very dangerous!!! good luck my friend!";
|
||||
inline const std::string NO_VALID_DATA = "no valid data";
|
||||
|
@ -52,8 +52,7 @@ auto main(int argc, char* args[]) -> int
|
||||
// trs::client::upload("https://file-examples.com/storage/feaf4c715066a139295358c/2017/11/file_example_MP3_700KB.mp3", "/mnt/raid/projects/trs/test.mp3");
|
||||
|
||||
trs::server srv;
|
||||
srv.init("test service");
|
||||
srv.set_api_url("/api");
|
||||
srv.init("test service", "/api");
|
||||
|
||||
srv.registration("healthcheck", worckspaces::inspector, worckspaces::provider);
|
||||
srv.run();
|
||||
|
Loading…
Reference in New Issue
Block a user