Portfolio/src/composables/useAPI.ts
Matthew L McPeak 4ee81a3ab1
All checks were successful
ci / build (push) Successful in 16s
ci / publish (push) Successful in 17s
Inital Commit
2026-06-18 11:56:32 -04:00

28 lines
781 B
TypeScript

import type { PortfolioData } from "@/data/portfolio";
import { useUtils } from "./useUtils";
export const useAPI = (baseURL = window.API_URL, key = window.API_KEY) => {
const { url } = useUtils();
const normalizedURL = url.normalizePath(baseURL.trim());
const generateURL = (path: string) => {
return normalizedURL + path;
};
const getPortfolioData = async () =>
fetch(generateURL("/keyvalue?key=portfolio"), {
headers: {
authorization: `Bearer ` + key.trim(),
},
})
.then((resp) => resp.json())
.then((data: { key: string; value: string }[]) =>
data.length > 0 && data[0] ? (JSON.parse(data[0].value) as PortfolioData) : undefined,
)
.catch(() => undefined);
return {
getPortfolioData,
};
};