2019-07-14 21:13:26 +00:00
|
|
|
#include <ESP8266React.h>
|
|
|
|
|
2019-09-28 20:29:46 +00:00
|
|
|
ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs):
|
|
|
|
_securitySettingsService(server, fs),
|
|
|
|
_wifiSettingsService(server, fs, &_securitySettingsService),
|
|
|
|
_apSettingsService(server, fs, &_securitySettingsService),
|
|
|
|
_ntpSettingsService(server, fs, &_securitySettingsService),
|
|
|
|
_otaSettingsService(server, fs, &_securitySettingsService),
|
2019-12-01 08:28:40 +00:00
|
|
|
_restartService(server, &_securitySettingsService),
|
2019-09-28 20:29:46 +00:00
|
|
|
_authenticationService(server, &_securitySettingsService),
|
|
|
|
_wifiScanner(server, &_securitySettingsService),
|
|
|
|
_wifiStatus(server, &_securitySettingsService),
|
|
|
|
_ntpStatus(server, &_securitySettingsService),
|
|
|
|
_apStatus(server, &_securitySettingsService),
|
|
|
|
_systemStatus(server, &_securitySettingsService) {
|
|
|
|
// Serve static resources from /www/
|
2019-07-14 21:13:26 +00:00
|
|
|
server->serveStatic("/js/", SPIFFS, "/www/js/");
|
|
|
|
server->serveStatic("/css/", SPIFFS, "/www/css/");
|
|
|
|
server->serveStatic("/fonts/", SPIFFS, "/www/fonts/");
|
|
|
|
server->serveStatic("/app/", SPIFFS, "/www/app/");
|
|
|
|
server->serveStatic("/favicon.ico", SPIFFS, "/www/favicon.ico");
|
|
|
|
|
|
|
|
// Serving all other get requests with "/www/index.htm"
|
|
|
|
// OPTIONS get a straight up 200 response
|
|
|
|
server->onNotFound([](AsyncWebServerRequest *request) {
|
|
|
|
if (request->method() == HTTP_GET) {
|
|
|
|
request->send(SPIFFS, "/www/index.html");
|
|
|
|
} else if (request->method() == HTTP_OPTIONS) {
|
|
|
|
request->send(200);
|
|
|
|
} else {
|
|
|
|
request->send(404);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Disable CORS if required
|
|
|
|
#if defined(ENABLE_CORS)
|
|
|
|
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", CORS_ORIGIN);
|
|
|
|
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Authorization");
|
|
|
|
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Credentials", "true");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-09-30 20:28:24 +00:00
|
|
|
void ESP8266React::begin() {
|
|
|
|
_securitySettingsService.begin();
|
|
|
|
_wifiSettingsService.begin();
|
|
|
|
_apSettingsService.begin();
|
|
|
|
_ntpSettingsService.begin();
|
|
|
|
_otaSettingsService.begin();
|
|
|
|
}
|
|
|
|
|
2019-07-14 21:13:26 +00:00
|
|
|
void ESP8266React::loop() {
|
|
|
|
_wifiSettingsService.loop();
|
|
|
|
_apSettingsService.loop();
|
|
|
|
_ntpSettingsService.loop();
|
|
|
|
_otaSettingsService.loop();
|
|
|
|
}
|