Ad auth option to getApi()

This commit is contained in:
Fred Boniface 2023-04-28 13:52:26 +01:00
parent 90734cd098
commit f525466b84
3 changed files with 18 additions and 2 deletions

View File

@ -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}`)

View File

@ -1,4 +1,5 @@
hideLoading()
versionDisplay()
async function findByOrigDest() {
showLoading()

View File

@ -63,7 +63,7 @@
<button id="reset" class="lookup-button" onclick="reset()">Reset</button>
<!-- Footer -->
<footer>
<p>Created by <a href="https://fredboniface.co.uk" target="_blank" rel="noreferrer noopener">Fred Boniface</a> - <span id="ver_str">dev</span></p>
<p>Created by <a href="https://fredboniface.co.uk" target="_blank" rel="noreferrer noopener">Fred Boniface</a> - <span id="ver_str">d</span></p>
</footer>
</body>
</html>