From d498cd12b4e8e7530b3f12fb67f0101266844e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Mon, 27 Jan 2025 14:47:21 +0100 Subject: [PATCH] serveStatic + CORS --- src/patrix/core/http.cpp | 11 ++++++++++- src/patrix/core/http.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/patrix/core/http.cpp b/src/patrix/core/http.cpp index e9b1ea4..d8abe63 100644 --- a/src/patrix/core/http.cpp +++ b/src/patrix/core/http.cpp @@ -1,8 +1,10 @@ #include +#include #include #include #include +#include "filesystem.h" #include "wifi.h" AsyncWebServer server(80); @@ -22,6 +24,7 @@ void httpReboot(AsyncWebServerRequest *request) { } void httpSetup() { + fsMount(); ws.onEvent([](AsyncWebSocket *socket, AsyncWebSocketClient *client, AwsEventType type, void *arg, unsigned char *message, unsigned length) { const char *t; switch (type) { @@ -49,11 +52,17 @@ void httpSetup() { }); server.addHandler(&ws); + server.serveStatic("/", LittleFS, "/http/"); server.on("/reboot", HTTP_GET, httpReboot); server.begin(); + DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); + DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT"); + DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type"); + httpSetUp = true; - info("Webserver started.");} + info("Webserver started."); +} void httpLoop() { if (!httpSetUp && isWiFiConnected()) { diff --git a/src/patrix/core/http.h b/src/patrix/core/http.h index 4126f0d..dc820d1 100644 --- a/src/patrix/core/http.h +++ b/src/patrix/core/http.h @@ -1,7 +1,7 @@ #ifndef PATRIX_HTTP_H #define PATRIX_HTTP_H -#include +#include extern AsyncWebServer server;