merge all URI handlers into a single dispatch function

This commit is contained in:
proddy
2026-05-19 21:28:30 +02:00
parent d670bc2b07
commit 3fd0573339
10 changed files with 225 additions and 124 deletions

View File

@@ -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/