From f525466b84f4be4338f0330ca5b2a866d2963ca7 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 28 Apr 2023 13:52:26 +0100 Subject: [PATCH] Ad auth option to getApi() --- js/lib.main.js | 17 ++++++++++++++++- js/pis.js | 1 + pis.html | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/js/lib.main.js b/js/lib.main.js index 1b60e7a..7fd6cb3 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -130,8 +130,23 @@ async function getApi(path,auth = false) { let apiVer = 'v1' let url = `${window.location.origin}/api/${apiVer}/${path}` log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`) + if (auth) { + let key = localStorage.getItem('uuid') + var options = { + method: "GET", + redirect: "follow", + headers: { + "uuid": key + } + } + } else { + var options = { + method: "GET", + redirect: "follow" + } + } try { - var resp = await fetch(url) + var resp = await fetch(url, options) var json = await resp.json() log(`resp.status: ${resp.status}`) log(`resp.json: ${json}`) diff --git a/js/pis.js b/js/pis.js index e373729..9456b31 100644 --- a/js/pis.js +++ b/js/pis.js @@ -1,4 +1,5 @@ hideLoading() +versionDisplay() async function findByOrigDest() { showLoading() diff --git a/pis.html b/pis.html index 449072a..9d38db2 100644 --- a/pis.html +++ b/pis.html @@ -63,7 +63,7 @@ \ No newline at end of file