@@ -205,18 +205,22 @@ void webserver_setup()
205
205
}
206
206
});
207
207
208
+ server.on (F (" /version" ), []() {
209
+ File file = SPIFFS.open (" /version" , " r" );
210
+ server.sendHeader (" Cache-Control" , " max-age=86400" );
211
+ server.streamFile (file, mime::mimeTable[mime::txt].mimeType );
212
+ file.close ();
213
+ });
214
+
208
215
// serves all SPIFFS Web file with 24hr max-age control
209
216
// to avoid multiple requests to ESP
210
217
server.serveStatic (" /font" , SPIFFS, " /font" , " max-age=86400" );
211
218
server.serveStatic (" /js" , SPIFFS, " /js" , " max-age=86400" );
212
219
server.serveStatic (" /css" , SPIFFS, " /css" , " max-age=86400" );
213
220
server.serveStatic (" /favicon.ico" , SPIFFS, " /favicon.ico" , " max-age=86400" );
214
- server.serveStatic (" /version" , SPIFFS, " /version" , " max-age=60" );
215
221
216
222
server.onNotFound (webserver_handle_notfound);
217
223
218
- // server.serveStatic("/", SPIFFS, "/", "max-age=86400");
219
-
220
224
// ask server to track these headers
221
225
const char *headerkeys[] = {" User-Agent" , " X-Forwarded-For" };
222
226
size_t headerkeyssize = sizeof (headerkeys) / sizeof (char *);
@@ -234,14 +238,14 @@ void webserver_loop()
234
238
235
239
bool webserver_handle_read (const String &path)
236
240
{
237
- Serial.printf_P (" webserver_handle_read: %s\n " , path.c_str ());
241
+ Serial.printf_P (PSTR ( " webserver_handle_read: %s\n " ) , path.c_str ());
238
242
239
243
if (path.endsWith (" /" ))
240
244
{
241
245
return false ;
242
246
}
243
247
244
- String contentType = esp8266webserver::StaticRequestHandler<WiFiServer>::getContentType (path); // Get the MIME type
248
+ String contentType = esp8266webserver::StaticRequestHandler<WiFiServer>::getContentType (path);
245
249
246
250
String real_path = path + " .gz" ;
247
251
if (!SPIFFS.exists (real_path)) // If there's a compressed version available
@@ -253,14 +257,14 @@ bool webserver_handle_read(const String &path)
253
257
real_path = path;
254
258
}
255
259
256
- File file = SPIFFS.open (real_path, " r" ); // Open the file
260
+ File file = SPIFFS.open (real_path, " r" );
257
261
258
262
server.sendHeader (" Cache-Control" , " max-age=86400" );
259
263
260
- size_t sent = server.streamFile (file, contentType); // Send it to the client
261
- file.close (); // Close the file again
264
+ size_t sent = server.streamFile (file, contentType);
265
+ file.close ();
262
266
263
- Serial.printf_P (" webserver_handle_read: %s %zu bytes\n " , real_path.c_str (), sent);
267
+ Serial.printf_P (PSTR ( " webserver_handle_read: %s %zu bytes\n " ) , real_path.c_str (), sent);
264
268
265
269
return true ;
266
270
}
0 commit comments