CORS fix
This commit is contained in:
		
							parent
							
								
									8caffd50b2
								
							
						
					
					
						commit
						156e095d4d
					
				| @ -1,7 +1,6 @@ | |||||||
| #pragma once | #pragma once | ||||||
| #include "LittleFS.h" | #include "LittleFS.h" | ||||||
| #include "ArduinoJson.h" | #include "ArduinoJson.h" | ||||||
| #define CONFIG_SIZE 0x4E |  | ||||||
| #define OFFSET_SSID 0x00 | #define OFFSET_SSID 0x00 | ||||||
| #define OFFSET_PASS 0x20 | #define OFFSET_PASS 0x20 | ||||||
| #define OFFSET_IP 0x40 | #define OFFSET_IP 0x40 | ||||||
| @ -10,6 +9,7 @@ | |||||||
| #define OFFSET_MODE 0x4C | #define OFFSET_MODE 0x4C | ||||||
| #define OFFSET_FAIL_TIMEOUT 0x4D | #define OFFSET_FAIL_TIMEOUT 0x4D | ||||||
| #define OFFSET_HOLD_TIME 0x4E | #define OFFSET_HOLD_TIME 0x4E | ||||||
|  | #define CONFIG_SIZE 0x4F | ||||||
| class Config | class Config | ||||||
| { | { | ||||||
| private: | private: | ||||||
|  | |||||||
| @ -45,7 +45,7 @@ bool WebConsole::init(Config *config, userdb::UserDb *userdb) | |||||||
|     _server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_GET, std::bind(&WebConsole::_getUser, this)); |     _server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_GET, std::bind(&WebConsole::_getUser, this)); | ||||||
|     _server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_PUT, std::bind(&WebConsole::_createUser, this)); |     _server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_PUT, std::bind(&WebConsole::_createUser, this)); | ||||||
|     _server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_POST, std::bind(&WebConsole::_updateUser, this)); |     _server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_POST, std::bind(&WebConsole::_updateUser, this)); | ||||||
|     _server->on(UriBraces("/api/config"), std::bind(&WebConsole::_settings, this)); |     _server->on(UriBraces("/api/config"), HTTPMethod::HTTP_POST, std::bind(&WebConsole::_settings, this)); | ||||||
|     _server->serveStatic("/", LittleFS, "/s/"); |     _server->serveStatic("/", LittleFS, "/s/"); | ||||||
|     _server->onNotFound(std::bind(&WebConsole::_handleUnknown, this)); |     _server->onNotFound(std::bind(&WebConsole::_handleUnknown, this)); | ||||||
|     return true; |     return true; | ||||||
| @ -83,6 +83,11 @@ uint8_t WebConsole::isInterceptingRfid() | |||||||
| } | } | ||||||
| bool WebConsole::_isAuth() | bool WebConsole::_isAuth() | ||||||
| { | { | ||||||
|  |     if (_server->method() == HTTPMethod::HTTP_OPTIONS) | ||||||
|  |     { | ||||||
|  |         _server->send(204); | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|     if (!_server->hasHeader("Authentification")) |     if (!_server->hasHeader("Authentification")) | ||||||
|     { |     { | ||||||
|         _server->send(401, "text/plain", "Error 401: Unauthorized (missing auth token)"); |         _server->send(401, "text/plain", "Error 401: Unauthorized (missing auth token)"); | ||||||
| @ -229,7 +234,12 @@ void WebConsole::_settings() | |||||||
|     } |     } | ||||||
|     else if (action.equals("get")) |     else if (action.equals("get")) | ||||||
|     { |     { | ||||||
|         _server->send(200, "text/json", "{\"SSID\":\"" + String(_config->SSID) + "\", \"PASS\":\"" + String(_config->PASS) + "\", \"ip\":\"" + IPAddress(_config->ip).toString() + "\", \"subnet\":\"" + IPAddress(_config->subnet).toString() + "\", \"gw\":\"" + IPAddress(_config->gw).toString() + "\", \"fail_timeout\":\"" + String(_config->fail_timeout) + "\", \"hold_time\":\"" + String(_config->hold_time) + "\"}"); |         _server->send(200, "text/json", "{\"SSID\":\"" + String(_config->SSID) + "\", \"PASS\":\"" + String(_config->PASS) + "\", \"ip\":\"" + IPAddress(_config->ip).toString() + "\", \"subnet\":\"" + IPAddress(_config->subnet).toString() + "\", \"gw\":\"" + IPAddress(_config->gw).toString() + "\", \"mode\":\"" + String(_config->mode) + "\", \"fail_timeout\":\"" + String(_config->fail_timeout) + "\", \"hold_time\":\"" + String(_config->hold_time) + "\"}"); | ||||||
|  |     } | ||||||
|  |     else if (action.equals("apply")) | ||||||
|  |     { | ||||||
|  |         _server->send(200, "text/json", "{\"status\":\"restarting\"}"); | ||||||
|  |         ESP.restart(); | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|         _server->send(404, "text/plain", "unknown action"); |         _server->send(404, "text/plain", "unknown action"); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user