handling CORS
davvalent

davvalent commited on 2023-03-15 16:33:56
Showing 1 changed files, with 9 additions and 2 deletions.

... ...
@@ -28,8 +28,15 @@
28 28
 
29 29
   );
30 30
 
31
-  // Cross-origin resource sharing (CORS)
32
-  header("Access-Control-Allow-Origin: https://ntnlv.ca");
31
+  /** Handling CORS */
32
+  $origin = getallheaders()['Origin'];
33
+  $dev = (str_contains($origin, 'localhost') || str_contains($origin, '127.0.0.1'))
34
+    ? true
35
+    : false;
36
+  $host_origin = ($dev)
37
+    ? $request_headers['Origin']
38
+    : "https://ntnlv.ca";
39
+  header('Access-Control-Allow-Origin: ' . $host_origin);
33 40
 
34 41
   $ep = ARC2::getStoreEndpoint($config);
35 42
 
36 43