This commit is contained in:
Proddy
2023-12-31 13:57:43 +01:00
parent 8bdd01f73f
commit 7b96baa9b8
6 changed files with 24 additions and 21 deletions

View File

@@ -1435,7 +1435,9 @@ void EMSESP::setupWeb() {
// esp8266React services has 13
// custom projects has around 23
webServer.config.max_uri_handlers = 80;
// webServer.config.uri_match_fn = NULL;
// webServer.config.uri_match_fn = NULL; // don't use wildcards
// webServer.config.task_priority = uxTaskPriorityGet(nullptr); // seems to make it slightly slower
// TODO add support for https
webServer.listen(80); // start the web server

View File

@@ -32,7 +32,6 @@ WebAPIService::WebAPIService(PsychicHttpServer * server, SecurityManager * secur
void WebAPIService::registerURI() {
// POST /api/{device}[/{hc|wwc|id}][/{name}]
// note: must explicity use 'Content-Type: application/json' in header
_server->on(EMSESP_API_SERVICE_PATH, HTTP_POST, [this](PsychicRequest * request, JsonVariant & json) {
// if no json body then treat it as a secure GET
if (!json.is<JsonObject>()) {
@@ -53,14 +52,6 @@ void WebAPIService::registerURI() {
return parse(request, input);
});
// GET - for when using GET query parameters, the old style from v2
// Note POST just to /api is no longer supported
_server->on("/api", HTTP_GET, [this](PsychicRequest * request) {
StaticJsonDocument<EMSESP_JSON_SIZE_SMALL> input_doc;
JsonObject input = input_doc.to<JsonObject>(); // empty input json
return parse(request, input);
});
// for settings
_server->on(GET_SETTINGS_PATH, HTTP_GET, _securityManager->wrapRequest(std::bind(&WebAPIService::getSettings, this, _1), AuthenticationPredicates::IS_ADMIN));
_server->on(GET_CUSTOMIZATIONS_PATH,
@@ -141,7 +132,7 @@ esp_err_t WebAPIService::parse(PsychicRequest * request, JsonObject & input) {
request->reply(ret_codes[return_code]); // exit with error code
}
api_count_++; // another succesful api call
api_count_++; // another successful api call
// if we're returning single values, just sent as plain text and not json
// https://github.com/emsesp/EMS-ESP32/issues/462#issuecomment-1093877210
@@ -151,7 +142,6 @@ esp_err_t WebAPIService::parse(PsychicRequest * request, JsonObject & input) {
}
// normal return
// TODO check if needed to add utf-8 here
response.setContentType("application/json; charset=utf-8"); // TODO doesn't seem to work
// response.addHeader("Connection", "close");

View File

@@ -19,7 +19,7 @@
#ifndef WebAPIService_h
#define WebAPIService_h
#define EMSESP_API_SERVICE_PATH "/api/*"
#define EMSESP_API_SERVICE_PATH "/api/?*"
#define GET_SETTINGS_PATH "/rest/getSettings"
#define GET_CUSTOMIZATIONS_PATH "/rest/getCustomizations"
#define GET_SCHEDULE_PATH "/rest/getSchedule"