123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "httpserver.h"
-
-
- bool HTTPServer::addRootFileHandler() {
-
- // //experimental, see doku.md
- // server.serveStatic("/compressed", LittleFS, "/compressed.html.gzip");
-
- this->serveStatic("", LittleFS, "/index.html");
- this->serveStatic("/", LittleFS, "/index.html");
- this->serveStatic("/#", LittleFS, "/index.html");
- this->serveStatic("/style.css", LittleFS, "/style.css");
- this->serveStatic("/input.js", LittleFS, "/input.js");
- this->serveStatic("/favicon.png", LittleFS, "/favicon.png");
-
- return true;
- }
-
-
- bool HTTPServer::addRootFileHandler_ls() {
- logf("addRootFileHandler_ls: %s\n\r", rootDir);
- Dir root = LittleFS.openDir(rootDir);
-
- while (root.next()) {
- const String& fName = "/" + root.fileName();
- const String& fName_gz = "/" + root.fileName() + ".gz";
- Serial.printf("Register Callback for: %s @ %s\n\r",
- fName.c_str(), fName_gz.c_str());
-
- // https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11
- on(fName, [this, fName, fName_gz]() {
-
- logf("addRootFileHandler_ls: %s\n\r", rootDir);
- File f = open(fName_gz.c_str());
- if (f)
- streamFile(f, mime::getContentType(fName));
- else
- send(404, "text/plain", "Failed to open file for reading");
- });
- }
- return true;
- }
|