From 90bfbda9c744211b73a02621c2c4cc10f3bfdce8 Mon Sep 17 00:00:00 2001 From: nedko Date: Mon, 22 Jun 2026 15:30:43 +0300 Subject: [PATCH] Handle trailing slashes --- main.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 869a97b..b79654d 100644 --- a/main.cpp +++ b/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char **argv) server = make_shared(); } - server->Get("/api/setup/", [](const httplib::Request& req, httplib::Response& res) + auto setup_handler = [](const httplib::Request& req, httplib::Response& res) { cout << req.headers.size() << endl; for (auto header : req.headers) @@ -72,13 +72,27 @@ int main(int argc, char **argv) cout << header.first << ": " << header.second << endl; } res.status = 400; - }); + }; - server->Post("/api/log/", [](const httplib::Request& req, httplib::Response& res) + auto log_handler = [](const httplib::Request& req, httplib::Response& res) { - cout << req.body << endl; + try + { + json j = json::parse(req.body); + cout << j.dump(4) << endl; + } + catch (const exception& e) + { + cout << req.body << endl; + } res.status = 200; - }); + }; + + server->Get("/api/setup/", setup_handler); + server->Get("/api/setup", setup_handler); + + server->Post("/api/log/", log_handler); + server->Post("/api/log", log_handler); server->listen(host, port);