diff --git a/src/network/CrossPointWebServer.cpp b/src/network/CrossPointWebServer.cpp index 0c6164b2..fbee83da 100644 --- a/src/network/CrossPointWebServer.cpp +++ b/src/network/CrossPointWebServer.cpp @@ -353,6 +353,15 @@ void CrossPointWebServer::handleJszip() const { } void CrossPointWebServer::handleNotFound() const { + // in AP mode, redirect unmatched browser/captive-portal requests to "/" so the OS auto-opens the browser + // API requests (/api/*) still return 404 so XHR errors surface correctly + // see https://en.wikipedia.org/wiki/Captive_portal#Detection + if (apMode && !server->uri().startsWith("/api/")) { + server->sendHeader("Location", "/", true); + server->send(302, "text/plain", ""); + return; + } + String message = "404 Not Found\n\n"; message += "URI: " + server->uri() + "\n"; server->send(404, "text/plain", message);