Browse Source

add CORS header to GET requests

Helmut Pozimski 5 years ago
parent
commit
08871c3628
1 changed files with 3 additions and 0 deletions
  1. 3 0
      jsonrtc/src/jsonrtc.c

+ 3 - 0
jsonrtc/src/jsonrtc.c

@@ -91,6 +91,7 @@ int handle_time(struct http_request *req) {
 			result_string = cJSON_Print(time_json);
 			cJSON_Delete(time_json);
 			http_response_header(req, "Content-Type", "application/json");
+            http_response_header(req, "Access-Control-Allow-Origin", "*");
 			http_response(req, 200, result_string, strlen(result_string));
 			return KORE_RESULT_OK;
 		}
@@ -188,6 +189,7 @@ int handle_wkalrm(struct http_request *req) {
 			result_string = cJSON_Print(alarm_json);
 			cJSON_Delete(alarm_json);
                         http_response_header(req, "Content-Type", "application/json");
+                        http_response_header(req, "Access-Control-Allow-Origin", "*");
                         http_response(req, 200, result_string, strlen(result_string));
                         return KORE_RESULT_OK;
 		} 
@@ -293,6 +295,7 @@ int handle_nvmem(struct http_request *req) {
 			result_object = cJSON_Print(json_response);
                         cJSON_Delete(json_response);
                         http_response_header(req, "Content-Type", "application/json");
+                        http_response_header(req, "Access-Control-Allow-Origin", "*");
 			http_response(req, 200, result_object, strlen(result_object));
 		} else {
                         result_string = "Error: could not read from nvmem\n";