kc token public key/token issue, path root set to 1

This commit is contained in:
h z
2024-12-06 10:04:03 +00:00
parent da1860a269
commit 6d96b658f0
7 changed files with 215 additions and 29 deletions

View File

@@ -1,3 +1,5 @@
import {data} from "react-router-dom";
const ongoingRequests = new Map();
@@ -40,9 +42,15 @@ export async function fetch_(url, init = {}, init_options = {}){
headers: {
...(init.headers || {}),
...(token ? {Authorization: `Bearer ${token}`} : {}),
...(init.method && ['PUT', 'POST'].includes(init.method.toUpperCase())
? {'Content-Type': 'application/json'}
: {}),
}
};
if(options.use_cache && ongoingRequests.has(options.cache_key)){
return ongoingRequests.get(options.cache_key);
}
const now = Date.now();
const cached_data = localStorage.getItem(options.cache_key);
if(options.use_cache && cached_data){
@@ -54,11 +62,13 @@ export async function fetch_(url, init = {}, init_options = {}){
try {
const fetchPromise = fetch(url, request_options)
.then((response) => {
if(!response.ok)
if(!response.ok) {
throw new Error(`RESPONSE_ERROR: ${response.status}`);
}
return response.json();
})
.then((data) => {
if (options.use_cache)
{
localStorage.setItem(
@@ -79,9 +89,6 @@ export async function fetch_(url, init = {}, init_options = {}){
}
throw error;
}
}