feat: GET node config endpoint
This commit is contained in:
@@ -37,6 +37,11 @@ void NodeService::registerEndpoints(ApiServer& api) {
|
||||
ParamSpec{String("labels"), true, String("body"), String("json"), {}, String("")}
|
||||
});
|
||||
|
||||
// Config endpoint for getting node configuration (without WiFi password)
|
||||
api.registerEndpoint("/api/node/config", HTTP_GET,
|
||||
[this](AsyncWebServerRequest* request) { handleGetConfigRequest(request); },
|
||||
std::vector<ParamSpec>{});
|
||||
|
||||
// Generic local event endpoint
|
||||
api.registerEndpoint("/api/node/event", HTTP_POST,
|
||||
[this](AsyncWebServerRequest* request) {
|
||||
@@ -233,3 +238,60 @@ void NodeService::handleConfigRequest(AsyncWebServerRequest* request) {
|
||||
request->send(500, "application/json", "{\"error\":\"Failed to save configuration\"}");
|
||||
}
|
||||
}
|
||||
|
||||
void NodeService::handleGetConfigRequest(AsyncWebServerRequest* request) {
|
||||
JsonDocument doc;
|
||||
|
||||
// WiFi Configuration (excluding password for security)
|
||||
JsonObject wifiObj = doc["wifi"].to<JsonObject>();
|
||||
wifiObj["ssid"] = ctx.config.wifi_ssid;
|
||||
wifiObj["connect_timeout_ms"] = ctx.config.wifi_connect_timeout_ms;
|
||||
wifiObj["retry_delay_ms"] = ctx.config.wifi_retry_delay_ms;
|
||||
|
||||
// Network Configuration
|
||||
JsonObject networkObj = doc["network"].to<JsonObject>();
|
||||
networkObj["udp_port"] = ctx.config.udp_port;
|
||||
networkObj["api_server_port"] = ctx.config.api_server_port;
|
||||
|
||||
// Cluster Configuration
|
||||
JsonObject clusterObj = doc["cluster"].to<JsonObject>();
|
||||
clusterObj["discovery_interval_ms"] = ctx.config.discovery_interval_ms;
|
||||
clusterObj["heartbeat_interval_ms"] = ctx.config.heartbeat_interval_ms;
|
||||
clusterObj["cluster_listen_interval_ms"] = ctx.config.cluster_listen_interval_ms;
|
||||
clusterObj["status_update_interval_ms"] = ctx.config.status_update_interval_ms;
|
||||
clusterObj["member_info_update_interval_ms"] = ctx.config.member_info_update_interval_ms;
|
||||
clusterObj["print_interval_ms"] = ctx.config.print_interval_ms;
|
||||
|
||||
// Node Status Thresholds
|
||||
JsonObject thresholdsObj = doc["thresholds"].to<JsonObject>();
|
||||
thresholdsObj["node_active_threshold_ms"] = ctx.config.node_active_threshold_ms;
|
||||
thresholdsObj["node_inactive_threshold_ms"] = ctx.config.node_inactive_threshold_ms;
|
||||
thresholdsObj["node_dead_threshold_ms"] = ctx.config.node_dead_threshold_ms;
|
||||
|
||||
// System Configuration
|
||||
JsonObject systemObj = doc["system"].to<JsonObject>();
|
||||
systemObj["restart_delay_ms"] = ctx.config.restart_delay_ms;
|
||||
systemObj["json_doc_size"] = ctx.config.json_doc_size;
|
||||
|
||||
// Memory Management
|
||||
JsonObject memoryObj = doc["memory"].to<JsonObject>();
|
||||
memoryObj["low_memory_threshold_bytes"] = ctx.config.low_memory_threshold_bytes;
|
||||
memoryObj["critical_memory_threshold_bytes"] = ctx.config.critical_memory_threshold_bytes;
|
||||
memoryObj["max_concurrent_http_requests"] = ctx.config.max_concurrent_http_requests;
|
||||
|
||||
// Custom Labels
|
||||
if (!ctx.config.labels.empty()) {
|
||||
JsonObject labelsObj = doc["labels"].to<JsonObject>();
|
||||
for (const auto& kv : ctx.config.labels) {
|
||||
labelsObj[kv.first.c_str()] = kv.second;
|
||||
}
|
||||
}
|
||||
|
||||
// Add metadata
|
||||
doc["version"] = "1.0";
|
||||
doc["retrieved_at"] = millis();
|
||||
|
||||
String json;
|
||||
serializeJson(doc, json);
|
||||
request->send(200, "application/json", json);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user