Portfolio/src/composables/useAPI.ts
Matthew L McPeak 29670b22ed
Some checks failed
ci / build (push) Failing after 10s
ci / publish (push) Has been skipped
Inital Commit
2026-06-18 10:53:05 -04:00

24 lines
699 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"))
.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,
};
};