mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-11 10:19:55 +03:00
minor uodates to routing
This commit is contained in:
@@ -1404,11 +1404,7 @@ EMSESP::EMSESP()
|
||||
|
||||
// add web server endpoint
|
||||
void EMSESP::handler(const char * uri, const char * contentType, const uint8_t * content, size_t len) {
|
||||
// remap to root
|
||||
if (strcmp(uri, "/index.html") == 0) {
|
||||
uri = "/";
|
||||
}
|
||||
webServer.on(uri, HTTP_GET, [contentType, content, len](PsychicRequest * request) {
|
||||
PsychicHttpRequestCallback fn = [contentType, content, len](PsychicRequest * request) {
|
||||
PsychicResponse response(request);
|
||||
response.setCode(200);
|
||||
response.setContentType(contentType);
|
||||
@@ -1416,7 +1412,17 @@ void EMSESP::handler(const char * uri, const char * contentType, const uint8_t *
|
||||
// response.addHeader("Content-Encoding", "br"); // Brotli - only works over HTTPS
|
||||
response.setContent(content, len);
|
||||
return response.send();
|
||||
});
|
||||
};
|
||||
|
||||
PsychicWebHandler * handler = new PsychicWebHandler();
|
||||
handler->onRequest(fn);
|
||||
webServer.on(uri, HTTP_GET, handler);
|
||||
|
||||
// Set default end-point for all non matching requests
|
||||
// this is easier than using webServer.onNotFound()
|
||||
if (strcmp(uri, "/index.html") == 0) {
|
||||
webServer.defaultEndpoint->setHandler(handler);
|
||||
}
|
||||
};
|
||||
|
||||
// configure web server
|
||||
@@ -1426,9 +1432,9 @@ void EMSESP::setupWeb() {
|
||||
// WWWData has 19 (in registerRoutes(handler)
|
||||
// esp8266React services has 13
|
||||
// custom projects has around 23
|
||||
webServer.config.max_uri_handlers = 70;
|
||||
webServer.config.max_uri_handlers = 80;
|
||||
|
||||
// TODO add support for HTTPS
|
||||
// TODO add support for https
|
||||
webServer.listen(80); // start the web server
|
||||
|
||||
DefaultHeaders::Instance().addHeader("Server", "EMS-ESP");
|
||||
@@ -1447,18 +1453,6 @@ void EMSESP::setupWeb() {
|
||||
webSchedulerService.registerURI(); // /rest/schedule
|
||||
webCustomEntityService.registerURI(); // /rest/customentities
|
||||
|
||||
webServer.onNotFound([](PsychicRequest * request) {
|
||||
if (request->method() == HTTP_GET) {
|
||||
Serial.printf("redirecting not found %s\n", request->uri().c_str()); // TODO remove debug
|
||||
String url = "http://" + request->host(); // TODO add support for https
|
||||
return request->redirect(url.c_str());
|
||||
} else if (request->method() == HTTP_OPTIONS) {
|
||||
return request->reply(200);
|
||||
} else {
|
||||
return request->reply(404);
|
||||
}
|
||||
});
|
||||
|
||||
// Add CORS if specified in the network settings
|
||||
esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
||||
if (networkSettings.enableCORS) {
|
||||
@@ -1498,7 +1492,7 @@ void EMSESP::start() {
|
||||
// do a quick scan of the filesystem to see if we have a /config folder
|
||||
// so we know if this is a new install or not
|
||||
#ifndef EMSESP_STANDALONE
|
||||
File root = LittleFS.open("/config");
|
||||
File root = LittleFS.open("/config"); // FS_CONFIG_DIRECTORY
|
||||
bool factory_settings = !root;
|
||||
if (!root) {
|
||||
#if defined(EMSESP_DEBUG)
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
// uses StaticJsonDocument
|
||||
#define EMSESP_JSON_SIZE_SMALL 256
|
||||
#define EMSESP_JSON_SIZE_MEDIUM 768
|
||||
#define EMSESP_JSON_SIZE_LARGE 1024 // used in forming HA config payloads, also in *AsyncJsonResponse
|
||||
#define EMSESP_JSON_SIZE_LARGE 1024 // used in forming HA config payloads
|
||||
|
||||
// used in larger buffers like DynamicJsonDocument
|
||||
#define EMSESP_JSON_SIZE_XLARGE 2048
|
||||
|
||||
@@ -683,7 +683,6 @@ std::string Helpers::toUpper(std::string const & s) {
|
||||
|
||||
// capitalizes one UTF-8 character in char array
|
||||
// works with Latin1 (1 byte), Polish amd some other (2 bytes) characters
|
||||
// TODO add special characters that occur in other supported languages
|
||||
#if defined(EMSESP_STANDALONE)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wtype-limits"
|
||||
|
||||
@@ -208,15 +208,13 @@ esp_err_t WebCustomizationService::device_entities(PsychicRequest * request) {
|
||||
PsychicJsonResponse response = PsychicJsonResponse(request, true, EMSESP_JSON_SIZE_XXXXLARGE, true); // is array and also msgpack
|
||||
JsonArray output = response.getRoot();
|
||||
|
||||
// TODO add back memory management
|
||||
// TODO add back memory managegement. Be careful we do need to free()/delete() any object we extend with new()
|
||||
// while (!response) {
|
||||
// delete response;
|
||||
// buffer -= 1024;
|
||||
// // response = new MsgpackAsyncJsonResponse(true, buffer);
|
||||
// }
|
||||
|
||||
// TODO add msgpack
|
||||
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice->unique_id() == id) {
|
||||
#ifndef EMSESP_STANDALONE
|
||||
|
||||
@@ -178,7 +178,7 @@ esp_err_t WebDataService::device_data(PsychicRequest * request) {
|
||||
PsychicJsonResponse response = PsychicJsonResponse(request, false, EMSESP_JSON_SIZE_XXXXLARGE, true); // is jsonobject and also msgpack
|
||||
JsonObject output = response.getRoot();
|
||||
|
||||
// TODO add back memory management?
|
||||
// TODO add back memory managegement. Be careful we do need to free()/delete() any object we extend with new()
|
||||
// check size
|
||||
// while (!response) {
|
||||
// delete response;
|
||||
|
||||
@@ -80,7 +80,7 @@ void WebLogService::registerURI() {
|
||||
return request->reply(200);
|
||||
});
|
||||
|
||||
// TODO remove?
|
||||
// TODO this can be removed when ported over
|
||||
// server->addHandler(&events_);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,11 @@ class WebLogService : public uuid::log::Handler {
|
||||
virtual void operator<<(std::shared_ptr<uuid::log::Message> message);
|
||||
|
||||
private:
|
||||
PsychicEventSource _events;
|
||||
SecurityManager * _securityManager;
|
||||
PsychicHttpServer * _server;
|
||||
|
||||
PsychicEventSource _events;
|
||||
|
||||
class QueuedLogMessage {
|
||||
public:
|
||||
QueuedLogMessage(unsigned long id, std::shared_ptr<uuid::log::Message> && content);
|
||||
@@ -65,9 +66,6 @@ class WebLogService : public uuid::log::Handler {
|
||||
void transmit(const QueuedLogMessage & message);
|
||||
char * messagetime(char * out, const uint64_t t, const size_t bufsize);
|
||||
|
||||
// TODO remove this?
|
||||
// PsychicJsonHandler setValues_; // for POSTs
|
||||
|
||||
esp_err_t fetchLog(PsychicRequest * request);
|
||||
esp_err_t getValues(PsychicRequest * request);
|
||||
esp_err_t setValues(PsychicRequest * request, JsonVariant & json);
|
||||
|
||||
Reference in New Issue
Block a user