first commit using PsychicHttp

This commit is contained in:
Proddy
2023-12-25 13:27:02 +01:00
parent 68cb94547e
commit 73a51ae4ad
169 changed files with 7162 additions and 12208 deletions

View File

@@ -1,13 +1,11 @@
#include <ESP8266React.h>
#include <WWWData.h>
ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
: _featureService(server)
, _securitySettingsService(server, fs)
, _networkSettingsService(server, fs, &_securitySettingsService)
, _wifiScanner(server, &_securitySettingsService)
ESP8266React::ESP8266React(PsychicHttpServer * server, FS * fs)
: _networkSettingsService(server, fs, &_securitySettingsService)
, _networkStatus(server, &_securitySettingsService)
, _featureService(server)
, _securitySettingsService(server, fs)
, _wifiScanner(server, &_securitySettingsService)
, _apSettingsService(server, fs, &_securitySettingsService)
, _apStatus(server, &_securitySettingsService, &_apSettingsService)
, _ntpSettingsService(server, fs, &_securitySettingsService)
@@ -20,40 +18,11 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
, _restartService(server, &_securitySettingsService)
, _factoryResetService(server, fs, &_securitySettingsService)
, _systemStatus(server, &_securitySettingsService) {
// Serve static resources from PROGMEM
WWWData::registerRoutes([server, this](const String & uri, const String & contentType, const uint8_t * content, size_t len) {
ArRequestHandlerFunction requestHandler = [contentType, content, len](AsyncWebServerRequest * request) {
AsyncWebServerResponse * response = request->beginResponse_P(200, contentType, content, len);
response->addHeader("Content-Encoding", "gzip");
// response->addHeader("Content-Encoding", "br"); // only works over HTTPS
request->send(response);
};
server->on(uri.c_str(), HTTP_GET, requestHandler);
// Serving non matching get requests with "/index.html"
// OPTIONS get a straight up 200 response
if (uri.equals("/index.html")) {
server->onNotFound([requestHandler](AsyncWebServerRequest * request) {
if (request->method() == HTTP_GET) {
requestHandler(request);
} else if (request->method() == HTTP_OPTIONS) {
request->send(200);
} else {
request->send(404);
}
});
}
});
}
// register services
void ESP8266React::begin() {
_networkSettingsService.begin();
_networkSettingsService.read([&](NetworkSettings & networkSettings) {
if (networkSettings.enableCORS) {
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", networkSettings.CORSOrigin);
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Authorization");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Credentials", "true");
}
});
_apSettingsService.begin();
_ntpSettingsService.begin();
_otaSettingsService.begin();
@@ -61,6 +30,35 @@ void ESP8266React::begin() {
_securitySettingsService.begin();
}
// create the web server endpoints
void ESP8266React::registerURI() {
_featureService.registerURI();
_authenticationService.registerURI();
_systemStatus.registerURI();
_networkSettingsService.registerURI();
_networkStatus.registerURI();
_apSettingsService.registerURI();
_apStatus.registerURI();
_ntpSettingsService.registerURI();
_ntpStatus.registerURI();
_mqttSettingsService.registerURI();
_mqttStatus.registerURI();
_securitySettingsService.registerURI();
_otaSettingsService.registerURI();
_restartService.registerURI();
_factoryResetService.registerURI();
_wifiScanner.registerURI();
_uploadFileService.registerURI();
}
void ESP8266React::loop() {
_networkSettingsService.loop();
_apSettingsService.loop();