Fixed 404 error when pressing refresh in webapp

This commit is contained in:
Thomas Basler 2022-07-01 23:32:11 +02:00
parent 1691274247
commit cf273c93e7
3 changed files with 7 additions and 8 deletions

View File

@ -33,8 +33,6 @@ private:
WebApiWsLiveClass _webApiWsLive;
void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
void onNotFound(AsyncWebServerRequest* request);
};
extern WebApiClass WebApi;

View File

@ -30,7 +30,6 @@ void WebApiClass::init()
_webApiWsLive.init(&_ws);
_server.onNotFound(std::bind(&WebApiClass::onNotFound, this, _1));
_server.begin();
}
@ -51,11 +50,7 @@ void WebApiClass::loop()
_ws.cleanupClients();
}
void WebApiClass::onNotFound(AsyncWebServerRequest* request)
{
// Handle Unknown Request
request->send(404, "text/plain", "404 Not Found");
}
void WebApiClass::onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len)
{

View File

@ -22,6 +22,12 @@ void WebApiWebappClass::init(AsyncWebServer* server)
request->send(response);
});
_server->onNotFound([](AsyncWebServerRequest* request) {
AsyncWebServerResponse* response = request->beginResponse_P(200, "text/html", file_index_html_start, file_index_html_end - file_index_html_start);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
});
_server->on("/index.html", HTTP_GET, [](AsyncWebServerRequest* request) {
AsyncWebServerResponse* response = request->beginResponse_P(200, "text/html", file_index_html_start, file_index_html_end - file_index_html_start);
response->addHeader("Content-Encoding", "gzip");