ESPAsyncWebServer
ESPAsyncWebServer copied to clipboard
server.on routing
if I make "/system" page and "/system/test" page only "/system" page is working when using ESP8266Webserver library it was working with no problem.
server->on("/system", HTTP_ANY, [](AsyncWebServerRequest* request) {
request->send(200, "text/plain", "system");
});
server->on("/system/test", HTTP_ANY, [](AsyncWebServerRequest* request) {
request->send(200, "text/plain", "system test");
});
is it normal behavior using this library?
I faced the same issue. However, I managed the following workaround:
- Convert all URIs into regex
- Enable compiler flag for regex support
To implement it:
// define a function to convert plaintext URIs into regex
String toRegex(const String &uri)
{
String result = url;
result.replace("/", "\\/");
return "^" + result + "(\\?.*)?$";
}
// use the toRegex function when routing
server->on(toRegex("/system").c_str(), HTTP_ANY, [](AsyncWebServerRequest* request) {
request->send(200, "text/plain", "system");
});
server->on(toRegex("/system/test").c_str(), HTTP_ANY, [](AsyncWebServerRequest* request) {
request->send(200, "text/plain", "system test");
});
Remember to add the compiler flag for regex support:
-DASYNCWEBSERVER_REGEX
@me-no-dev Is there any reason that the AsyncWebServer is not using the Uri class that comes with ESP8266WebServer?
It made URI Definition much easier and cleaner (using UriBraces, UriRegex and such).
I might be able to create a pull request.