Fixed 404 error when pressing refresh in webapp
This commit is contained in:
parent
1691274247
commit
cf273c93e7
@ -33,8 +33,6 @@ private:
|
|||||||
WebApiWsLiveClass _webApiWsLive;
|
WebApiWsLiveClass _webApiWsLive;
|
||||||
|
|
||||||
void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
|
void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
|
||||||
|
|
||||||
void onNotFound(AsyncWebServerRequest* request);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern WebApiClass WebApi;
|
extern WebApiClass WebApi;
|
||||||
@ -30,7 +30,6 @@ void WebApiClass::init()
|
|||||||
|
|
||||||
_webApiWsLive.init(&_ws);
|
_webApiWsLive.init(&_ws);
|
||||||
|
|
||||||
_server.onNotFound(std::bind(&WebApiClass::onNotFound, this, _1));
|
|
||||||
_server.begin();
|
_server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,11 +50,7 @@ void WebApiClass::loop()
|
|||||||
_ws.cleanupClients();
|
_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)
|
void WebApiClass::onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -22,6 +22,12 @@ void WebApiWebappClass::init(AsyncWebServer* server)
|
|||||||
request->send(response);
|
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) {
|
_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);
|
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");
|
response->addHeader("Content-Encoding", "gzip");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user