ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

httpserver.cpp 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "httpserver.h"
  2. bool HTTPServer::addRootFileHandler() {
  3. // //experimental, see doku.md
  4. // server.serveStatic("/compressed", LittleFS, "/compressed.html.gzip");
  5. this->serveStatic("", LittleFS, "/index.html");
  6. this->serveStatic("/", LittleFS, "/index.html");
  7. this->serveStatic("/#", LittleFS, "/index.html");
  8. this->serveStatic("/style.css", LittleFS, "/style.css");
  9. this->serveStatic("/input.js", LittleFS, "/input.js");
  10. this->serveStatic("/favicon.png", LittleFS, "/favicon.png");
  11. return true;
  12. }
  13. bool HTTPServer::addRootFileHandler_ls() {
  14. logf("addRootFileHandler_ls: %s\n\r", rootDir);
  15. Dir root = LittleFS.openDir(rootDir);
  16. while (root.next()) {
  17. const String& fName = "/" + root.fileName();
  18. const String& fName_gz = "/" + root.fileName() + ".gz";
  19. Serial.printf("Register Callback for: %s @ %s\n\r",
  20. fName.c_str(), fName_gz.c_str());
  21. // https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11
  22. on(fName, [this, fName, fName_gz]() {
  23. logf("addRootFileHandler_ls: %s\n\r", rootDir);
  24. File f = open(fName_gz.c_str());
  25. if (f)
  26. streamFile(f, mime::getContentType(fName));
  27. else
  28. send(404, "text/plain", "Failed to open file for reading");
  29. });
  30. }
  31. return true;
  32. }