Proper way of choosing which file to serve on web server
Posted: Thu Jul 18, 2019 4:01 pm
I want my ESP32 to serve local SPIFFS file, when it's not connected to my router or internet, in general.
Then, when there's an internet connection, I want it to serve files from CDN.
Is this the right way of doing so? It doesn't work for me.
Then, when there's an internet connection, I want it to serve files from CDN.
Is this the right way of doing so? It doesn't work for me.
Code: Select all
// Bootstrap CSS
server.on("/bootstrap.min.css", HTTP_GET, [](AsyncWebServerRequest* request) {
if (WiFi.status() == WL_CONNECTED) {
request->send(200, "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css", "text/css");
} else {
AsyncWebServerResponse* response = request->beginResponse(SPIFFS, "/bootstrap.min.css.gz", "text/css");
response->addHeader("Content-Encoding", "gzip");
request->send(response);
}
});