From: Chris Hofstaedtler Date: Wed, 3 Aug 2022 18:48:16 +0000 (+0200) Subject: rec: split config for fetch out of get_json X-Git-Tag: rec-4.8.0-alpha1~65^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de8d4ba40edbbefcefd29c1597948c60f3d8280a;p=thirdparty%2Fpdns.git rec: split config for fetch out of get_json 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. --- diff --git a/pdns/recursordist/html/local-2022.js b/pdns/recursordist/html/local-2022.js index 93af0ba5c4..3e653c9598 100644 --- a/pdns/recursordist/html/local-2022.js +++ b/pdns/recursordist/html/local-2022.js @@ -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));