From fe8d2974eafc7ebfacb81aab308dfe7cb27725b5 Mon Sep 17 00:00:00 2001 From: Patedam Date: Tue, 3 Mar 2026 14:31:01 -0500 Subject: [PATCH] feat: Add HTTP server with static file serving from LittleFS, system API endpoints, and CORS support. --- Provider/main/http_server.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Provider/main/http_server.cpp b/Provider/main/http_server.cpp index 9f1e414..73ccd3b 100644 --- a/Provider/main/http_server.cpp +++ b/Provider/main/http_server.cpp @@ -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 } }