diff --git a/data/static/index.html b/data/static/index.html new file mode 100644 index 00000000..66320301 --- /dev/null +++ b/data/static/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/data/static/index.html.gz b/data/static/index.html.gz deleted file mode 100644 index 4880f9ca..00000000 Binary files a/data/static/index.html.gz and /dev/null differ diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index 3577c9c0..f0303418 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -350,7 +350,8 @@ void handleStaticBrowse(HTTPRequest *req, HTTPResponse *res) modifiedFile.remove((modifiedFile.length() - 3), 3); res->print("" + String(file.name()).substring(1) + ""); } else { - res->print("" + String(file.name()).substring(1) + ""); + res->print("" + String(file.name()).substring(1) + + ""); } res->println(""); res->println(""); @@ -699,9 +700,35 @@ void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res) void handleRoot(HTTPRequest *req, HTTPResponse *res) { res->setHeader("Content-Type", "text/html"); - res->setHeader("Content-Encoding", "gzip"); - File file = SPIFFS.open("/static/index.html.gz"); + std::string filename = "/static/index.html"; + std::string filenameGzip = "/static/index.html.gz"; + + if (!SPIFFS.exists(filename.c_str()) && !SPIFFS.exists(filenameGzip.c_str())) { + // Send "404 Not Found" as response, as the file doesn't seem to exist + res->setStatusCode(404); + res->setStatusText("Not found"); + res->println("404 Not Found"); + res->printf("

File not found: %s

\n", filename.c_str()); + return; + } + + // Try to open the file from SPIFFS + File file; + + if (SPIFFS.exists(filename.c_str())) { + file = SPIFFS.open(filename.c_str()); + if (!file.available()) { + DEBUG_MSG("File not available - %s\n", filename.c_str()); + } + + } else if (SPIFFS.exists(filenameGzip.c_str())) { + file = SPIFFS.open(filenameGzip.c_str()); + res->setHeader("Content-Encoding", "gzip"); + if (!file.available()) { + DEBUG_MSG("File not available\n"); + } + } // Read the file from SPIFFS and write it to the HTTP response body size_t length = 0;