Proper way of choosing which file to serve on web server

Nogla1
Posts: 3
Joined: Sun Jul 14, 2019 10:19 am

Proper way of choosing which file to serve on web server

Postby Nogla1 » 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.

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);
        }
    });

Who is online

Users browsing this forum: Bing [Bot] and 106 guests