Web Server - Arduino

Use wildcard server route

# For use with ESPAsyncWebServer

Basically, see this example file for info:
    https://github.com/me-no-dev/ESPAsyncWebServer/blob/master/examples/regex_patterns/regex_patterns.ino

# Note the required additional build flag at the top:

Linux: ~/.arduino15/packages/espxxxx/hardware/espxxxx/{version}/platform.local.txt

compiler.cpp.extra_flags=-DASYNCWEBSERVER_REGEX=1

    

Wildcard Server Route for arbitrary static files

# So the route on the server worked, but I got ERR_CONNECTION_RESET's on these
# So something is happening that is restricting the passing of these.

server.on("^\\/(.+)$", HTTP_GET, [](AsyncWebServerRequest *request){
  String filename = request->pathArg(0);
  String suffix = filename.substring(filename.lastIndexOf(".") + 1);
  suffix.toLowerCase();
  String contentType;

  if (suffix == "html") {
      contentType ="text/html";
  } else if (suffix == "css") {
      contentType ="text/css";
  } else if (suffix == "js") {
      contentType ="text/javascript";
  } else if (suffix == "gif") {
      contentType ="image/gif";
  } else if (suffix == "png") {
      contentType ="image/png";
  } else if (suffix == "jpg" || suffix == "jpeg") {
      contentType ="image/jpeg";
  } else {
      contentType ="text/plain";
  }
  request->send(SPIFFS, "/" + filename, contentType);
});