From b7eee35ce4ff0965b999224c1b57dca4191f5306 Mon Sep 17 00:00:00 2001 From: mrv777 Date: Mon, 4 Nov 2024 22:31:40 -0600 Subject: [PATCH 1/2] fix: Better restart feedback & attempt to fix CORS --- .../src/app/components/swarm/swarm.component.ts | 12 +++++++++--- main/http_server/http_server.c | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/main/http_server/axe-os/src/app/components/swarm/swarm.component.ts b/main/http_server/axe-os/src/app/components/swarm/swarm.component.ts index 5df3254e..1edf21cd 100644 --- a/main/http_server/axe-os/src/app/components/swarm/swarm.component.ts +++ b/main/http_server/axe-os/src/app/components/swarm/swarm.component.ts @@ -132,10 +132,16 @@ export class SwarmComponent implements OnInit, OnDestroy { } public restart(axe: any) { - this.systemService.restart(`http://${axe.IP}`).subscribe(res => { - + this.systemService.restart(`http://${axe.IP}`).pipe( + catchError(error => { + this.toastr.error('Failed to restart device', 'Error'); + return of(null); + }) + ).subscribe(res => { + if (res !== null) { + this.toastr.success('Bitaxe restarted', 'Success'); + } }); - this.toastr.success('Success!', 'Bitaxe restarted'); } public remove(axeOs: any) { diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index e19fd152..78a7e628 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -320,6 +320,12 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req) static esp_err_t POST_restart(httpd_req_t * req) { + // Set CORS headers + if (set_cors_headers(req) != ESP_OK) { + httpd_resp_send_500(req); + return ESP_FAIL; + } + ESP_LOGI(TAG, "Restarting System because of API Request"); // Send HTTP response before restarting @@ -710,6 +716,10 @@ esp_err_t start_rest_server(void * pvParameters) .uri = "/api/system/restart", .method = HTTP_POST, .handler = POST_restart, .user_ctx = rest_context}; httpd_register_uri_handler(server, &system_restart_uri); + httpd_uri_t system_restart_options_uri = { + .uri = "/api/system/restart", .method = HTTP_OPTIONS, .handler = handle_options_request, .user_ctx = NULL}; + httpd_register_uri_handler(server, &system_restart_options_uri); + httpd_uri_t update_system_settings_uri = { .uri = "/api/system", .method = HTTP_PATCH, .handler = PATCH_update_settings, .user_ctx = rest_context}; httpd_register_uri_handler(server, &update_system_settings_uri); From 2046719d2c523886ad814c54031604b19bbd6dad Mon Sep 17 00:00:00 2001 From: mrv777 Date: Wed, 6 Nov 2024 22:05:39 -0600 Subject: [PATCH 2/2] fix: Set CORS headers should return ESP_OK --- main/http_server/http_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index 78a7e628..fe5910e3 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -323,7 +323,7 @@ static esp_err_t POST_restart(httpd_req_t * req) // Set CORS headers if (set_cors_headers(req) != ESP_OK) { httpd_resp_send_500(req); - return ESP_FAIL; + return ESP_OK; } ESP_LOGI(TAG, "Restarting System because of API Request");