Added test api URL, configured static files caching
This commit is contained in:
parent
45928917fa
commit
262838bb42
1
ESP32/data/www
Symbolic link
1
ESP32/data/www
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../WebApp/www
|
@ -30,7 +30,19 @@ void setup()
|
|||||||
Serial.print("Wifi connected, ip=");
|
Serial.print("Wifi connected, ip=");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html");
|
server.on("/api/status", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
|
int batteryVoltage = random(30000, 42000);
|
||||||
|
char json[128];
|
||||||
|
sprintf(json, "{\"v\":%d}", batteryVoltage);
|
||||||
|
request->send(200, "text/json", json);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Special case to send index.html without caching
|
||||||
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(SPIFFS, "/www/index.html", "text/html"); });
|
||||||
|
server.serveStatic("/index.html", SPIFFS, "/www/index.html");
|
||||||
|
|
||||||
|
// Other static files are cached (index.html knows whether to ignore caching or not for each file)
|
||||||
|
server.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=5184000");
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
Serial.println("HTTP server started");
|
Serial.println("HTTP server started");
|
||||||
|
Loading…
Reference in New Issue
Block a user