Handle trailing slashes
This commit is contained in:
22
main.cpp
22
main.cpp
@@ -64,7 +64,7 @@ int main(int argc, char **argv)
|
|||||||
server = make_shared<httplib::Server>();
|
server = make_shared<httplib::Server>();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
cout << req.headers.size() << endl;
|
||||||
for (auto header : req.headers)
|
for (auto header : req.headers)
|
||||||
@@ -72,13 +72,27 @@ int main(int argc, char **argv)
|
|||||||
cout << header.first << ": " << header.second << endl;
|
cout << header.first << ": " << header.second << endl;
|
||||||
}
|
}
|
||||||
res.status = 400;
|
res.status = 400;
|
||||||
});
|
};
|
||||||
|
|
||||||
server->Post("/api/log/", [](const httplib::Request& req, httplib::Response& res)
|
auto log_handler = [](const httplib::Request& req, httplib::Response& res)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
json j = json::parse(req.body);
|
||||||
|
cout << j.dump(4) << endl;
|
||||||
|
}
|
||||||
|
catch (const exception& e)
|
||||||
{
|
{
|
||||||
cout << req.body << endl;
|
cout << req.body << endl;
|
||||||
|
}
|
||||||
res.status = 200;
|
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);
|
server->listen(host, port);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user