mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-06-14 11:56:32 +03:00
merge all URI handlers into a single dispatch function
This commit is contained in:
@@ -25,10 +25,14 @@ uint16_t WebAPIService::api_fails_ = 0;
|
||||
|
||||
WebAPIService::WebAPIService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||
: _securityManager(securityManager) {
|
||||
AsyncCallbackJsonWebHandler * jsonHandler = new AsyncCallbackJsonWebHandler(EMSESP_API_SERVICE_PATH);
|
||||
jsonHandler->setMethod(HTTP_POST | HTTP_GET);
|
||||
jsonHandler->onRequest([this](AsyncWebServerRequest * request, JsonVariant json) { webAPIService(request, json); });
|
||||
server->addHandler(jsonHandler);
|
||||
// parse() does its own per-request admin check (with notoken_api), so no predicate.
|
||||
// /api also matches /api/<device>/<entity> via the route's backward-compatible URI matcher.
|
||||
securityManager->addEndpoint(
|
||||
server,
|
||||
EMSESP_API_SERVICE_PATH,
|
||||
AuthenticationPredicates::NONE_REQUIRED,
|
||||
[this](AsyncWebServerRequest * request, JsonVariant json) { webAPIService(request, json); },
|
||||
HTTP_POST | HTTP_GET);
|
||||
}
|
||||
|
||||
// POST|GET api/
|
||||
|
||||
@@ -32,9 +32,6 @@ WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * security
|
||||
[this](AsyncWebServerRequest * request, JsonVariant json) { getSetValues(request, json); },
|
||||
HTTP_ANY);
|
||||
|
||||
// Add authentication filter to EventSource
|
||||
// EventSource (SSE) cannot use custom headers, so authentication is done via URL parameter
|
||||
// events_.setFilter(securityManager->filterRequest(AuthenticationPredicates::IS_AUTHENTICATED));
|
||||
server->addHandler(&events_);
|
||||
}
|
||||
|
||||
@@ -211,6 +208,7 @@ void WebLogService::getSetValues(AsyncWebServerRequest * request, JsonVariant js
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// POST - write the settings
|
||||
level_ = json["level"];
|
||||
maximum_log_messages_ = json["max_messages"];
|
||||
@@ -234,6 +232,7 @@ void WebLogService::getSetValues(AsyncWebServerRequest * request, JsonVariant js
|
||||
settings.weblog_buffer = maximum_log_messages_;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
|
||||
request->send(200); // OK
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user