]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: split config for fetch out of get_json
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Wed, 3 Aug 2022 18:48:16 +0000 (20:48 +0200)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 16 Aug 2022 08:27:34 +0000 (10:27 +0200)
Makes for easier development of the embedded JS/HTML files.
To use this, use the commented out fetchConfig, and open index.html
in a browser directly from the filesystem.

pdns/recursordist/html/local-2022.js

index 93af0ba5c4a82afd85c3f3c7da9f6196b4d2dfc8..3e653c959805e9bff4306d3db4bfac94e1f79c43 100644 (file)
@@ -1,16 +1,29 @@
 "use strict";
 
-// var moment= require('moment');
+const fetchConfig = {
+    baseURL: window.location,
+    mode: 'same-origin',
+    headers: {'Accept': 'application/json'},
+};
+/*
+// Useful for development of the embedded webserver files.
+const fetchConfig = {
+    baseURL: 'http://127.0.0.1:8083/',
+    mode: 'cors',
+    headers: {'Accept': 'application/json', 'X-API-Key': 'changeme'},
+};
+*/
+
 var gdata = {};
 
 function get_json(url, params) {
-    const realURL = new URL(url + '?' + (new URLSearchParams(params)).toString(), window.location);
+    const realURL = new URL(url + '?' + (new URLSearchParams(params)).toString(), fetchConfig.baseURL);
     return new Promise((resolve, reject) => {
         fetch(realURL, {
             method: 'GET',
-            mode: 'same-origin',
+            mode: fetchConfig.mode,
             cache: 'no-cache',
-            headers: {'Accept': 'application/json'},
+            headers: fetchConfig.headers,
         }).then((response) => {
             if (response.ok) {
                 response.json().then((json) => resolve(json));