frontend/src/routes/hedge-funds/+page.ts
2024-08-16 13:40:24 +02:00

36 lines
724 B
TypeScript

import { getCache, setCache } from '$lib/store';
export const load = async ({parent}) => {
const getAllHedgeFunds = async () => {
const cachedData = getCache('', 'getAllHedgeFunds');
if (cachedData) {
return cachedData;
}
const { apiURL, apiKey } = await parent();
const response = await fetch(apiURL+'/all-hedge-funds', {
method: 'GET',
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey
},
});
const output = await response.json();
setCache('', output, 'getAllHedgeFunds');
return output;
};
// Make sure to return a promise
return {
getAllHedgeFunds: await getAllHedgeFunds()
};
};