Add a unified observability interface for applications with multiple networks
🧪 Test / test (push) Successful in 6m9s
🧪 Test / test (push) Successful in 6m9s
This commit is contained in:
@@ -355,12 +355,14 @@ class WebDebugServer {
|
||||
public:
|
||||
using SnapshotFn = std::function<std::string()>;
|
||||
|
||||
explicit WebDebugServer(uint16_t port, SnapshotFn fn)
|
||||
: port_(port), snapshot_fn_(std::move(fn)) {}
|
||||
explicit WebDebugServer(uint16_t port, SnapshotFn fn,
|
||||
const char* custom_html = nullptr)
|
||||
: port_(port), snapshot_fn_(std::move(fn))
|
||||
, html_(custom_html ? custom_html : HTML) {}
|
||||
|
||||
void start() {
|
||||
svr_.Get("/", [](const httplib::Request&, httplib::Response& res) {
|
||||
res.set_content(HTML, "text/html");
|
||||
svr_.Get("/", [this](const httplib::Request&, httplib::Response& res) {
|
||||
res.set_content(html_, "text/html");
|
||||
});
|
||||
svr_.Get("/api/snapshot", [this](const httplib::Request&, httplib::Response& res) {
|
||||
res.set_content(snapshot_fn_(), "application/json");
|
||||
@@ -381,10 +383,11 @@ public:
|
||||
WebDebugServer& operator=(const WebDebugServer&) = delete;
|
||||
|
||||
private:
|
||||
uint16_t port_;
|
||||
SnapshotFn snapshot_fn_;
|
||||
uint16_t port_;
|
||||
SnapshotFn snapshot_fn_;
|
||||
const char* html_;
|
||||
httplib::Server svr_;
|
||||
std::thread thread_;
|
||||
std::thread thread_;
|
||||
};
|
||||
|
||||
} // namespace kpn::web_debug
|
||||
|
||||
Reference in New Issue
Block a user