feat: Add HTTP server with static file serving from LittleFS, system API endpoints, and CORS support.
This commit is contained in:
@@ -8,6 +8,10 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_vfs.h"
|
||||
|
||||
#ifdef CONFIG_CALENDINK_DEPLOY_WEB_PAGES
|
||||
#include "esp_littlefs.h"
|
||||
#endif
|
||||
|
||||
// Project
|
||||
#include "api/system/info.cpp"
|
||||
#include "api/system/reboot.cpp"
|
||||
@@ -171,6 +175,33 @@ internal esp_err_t cors_options_handler(httpd_req_t *req)
|
||||
|
||||
internal httpd_handle_t start_webserver(void)
|
||||
{
|
||||
#ifdef CONFIG_CALENDINK_DEPLOY_WEB_PAGES
|
||||
esp_vfs_littlefs_conf_t conf = {};
|
||||
conf.base_path = "/www";
|
||||
conf.partition_label = "www";
|
||||
conf.format_if_mount_failed = false;
|
||||
conf.dont_mount = false;
|
||||
esp_err_t ret = esp_vfs_littlefs_register(&conf);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
if (ret == ESP_FAIL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to mount or format filesystem");
|
||||
}
|
||||
else if (ret == ESP_ERR_NOT_FOUND)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to find LittleFS partition");
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to initialize LittleFS (%s)", esp_err_to_name(ret));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "LittleFS mounted on /www");
|
||||
}
|
||||
#endif
|
||||
http_server_data_t *rest_context =
|
||||
(http_server_data_t *)calloc(1, sizeof(http_server_data_t));
|
||||
if (rest_context == NULL)
|
||||
@@ -221,5 +252,8 @@ internal void stop_webserver(httpd_handle_t server)
|
||||
if (server)
|
||||
{
|
||||
httpd_stop(server);
|
||||
#ifdef CONFIG_CALENDINK_DEPLOY_WEB_PAGES
|
||||
esp_vfs_littlefs_unregister("www");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user