diff --git a/ESPWebThingAdapter.h b/ESPWebThingAdapter.h index 0a27acc..9df8126 100644 --- a/ESPWebThingAdapter.h +++ b/ESPWebThingAdapter.h @@ -58,10 +58,16 @@ class WebThingAdapter { DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); + DefaultHeaders::Instance().addHeader( + "Access-Control-Allow-Headers", + "Origin, X-Requested-With, Content-Type, Accept"); this->server.onNotFound(std::bind(&WebThingAdapter::handleUnknown, this, std::placeholders::_1)); + this->server.on("/*", HTTP_OPTIONS, + std::bind(&WebThingAdapter::handleOptions, this, + std::placeholders::_1)); this->server.on("/", HTTP_GET, std::bind(&WebThingAdapter::handleThings, this, std::placeholders::_1)); @@ -333,6 +339,13 @@ class WebThingAdapter { request->send(404); } + void handleOptions(AsyncWebServerRequest *request) { + if (!verifyHost(request)) { + return; + } + request->send(204); + } + void handleThings(AsyncWebServerRequest *request) { if (!verifyHost(request)) { return; diff --git a/EthernetWebThingAdapter.h b/EthernetWebThingAdapter.h index 675e6dd..1cb73ba 100644 --- a/EthernetWebThingAdapter.h +++ b/EthernetWebThingAdapter.h @@ -411,6 +411,8 @@ class WebThingAdapter { client.println("Access-Control-Allow-Origin: *"); client.println( "Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); + client.println("Access-Control-Allow-Headers: " + "Origin, X-Requested-With, Content-Type, Accept"); client.println("Content-Type: application/json"); client.println("Connection: close"); client.println(); diff --git a/WiFi101WebThingAdapter.h b/WiFi101WebThingAdapter.h index 2f522b1..72a047e 100644 --- a/WiFi101WebThingAdapter.h +++ b/WiFi101WebThingAdapter.h @@ -397,6 +397,8 @@ class WebThingAdapter { client.println("Access-Control-Allow-Origin: *"); client.println( "Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); + client.println("Access-Control-Allow-Headers: " + "Origin, X-Requested-With, Content-Type, Accept"); client.println("Content-Type: application/json"); client.println("Connection: close"); client.println(); diff --git a/examples/PlatformIO/TextDisplay/platformio.ini b/examples/PlatformIO/TextDisplay/platformio.ini index a2cc702..badf7fc 100644 --- a/examples/PlatformIO/TextDisplay/platformio.ini +++ b/examples/PlatformIO/TextDisplay/platformio.ini @@ -23,30 +23,6 @@ lib_deps = Adafruit SSD1306 monitor_speed = 115200 -[env:d1] -platform = espressif8266 -board = d1 -framework = arduino -lib_deps = - ${global.lib_deps} - ESP Async WebServer -lib_ignore = WiFi101 -lib_ldf_mode = deep+ -monitor_speed = ${global.monitor_speed} - -[env:nodemcuv2] -platform = espressif8266 -board = nodemcuv2 -framework = arduino -lib_deps = - ${global.lib_deps} - ESP Async WebServer -lib_ignore = - ArduinoMDNS - WiFi101 -lib_ldf_mode = deep+ -monitor_speed = ${global.monitor_speed} - [env:esp32dev] platform = espressif32 board = esp32dev diff --git a/library.json b/library.json index 89478b0..a2d180b 100644 --- a/library.json +++ b/library.json @@ -2,7 +2,7 @@ "name": "webthing-arduino", "description": "A library for creating Web Things using the Web of Things API. Runs on ESP8266, ESP32, Ethernet, and WiFi101-compatible boards. Compatible with the Mozilla WebThings Gateway.", "keywords": "Communication", - "version": "0.11.1", + "version": "0.11.2", "authors": { "name": "Mozilla IoT " }, @@ -14,7 +14,7 @@ "license": "Mozilla Public License Version 2.0", "platforms": "espressif8266,espressif32,atmelavr", "dependencies": { - "ArduinoJson": "6.13.0" + "ArduinoJson": "6.15.0" }, "export": { "include": diff --git a/library.properties b/library.properties index 65e1f2b..cf20a2e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=webthing-arduino -version=0.11.1 +version=0.11.2 author=Mozilla IoT maintainer=James Hobin sentence=A library for creating Web Things using the Web of Things API